dprint / dprint

Pluggable and configurable code formatting platform written in Rust.

Home Page:https://dprint.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why is the formatting not parallel when formatting a single file?

doox911-opensource opened this issue · comments

OS: Windows 11 Pro; WSL 2; 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz 2.80 GHz; RAM 16gb

Dprint version: 0.41.0

Formatted file: https://github.com/Nilstrieb/jsonformat/blob/master/benches/large-file.json.

Run: time ./node_modules/.bin/dprint fmt --incremental=false ./temp/json/25MB.json

Output(cold start-up):

Formatted 1 file.

real    0m6.352s
user    0m5.003s
sys     0m0.493s

Output(hot start-up):

Formatted 1 file.

real    0m5.304s
user    0m4.710s
sys     0m0.223s

For example, prettier:

Run: time ./node_modules/.bin/prettier --write --log-level=silent ./temp/json/25MB.json

real    0m13.600s
user    0m26.097s
sys     0m1.530s
  1. It's a lot more complexity to use multi-threading to format a single file. It's way simpler for formatting to be synchronous.
  2. It's likely slower when formatting a large amount of files due to the introduced multi-threading overhead within formatting.
  3. It's difficult to do with Wasm. I'm not sure the state of Wasm threads or how that could work efficiently (ex. would each plugin need a thread pool or could it share dprint's thread pool).