Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider replacing prettier with biome for faster formatting #95

Open
0xdevalias opened this issue Jan 1, 2024 · 5 comments · May be fixed by #105
Open

Consider replacing prettier with biome for faster formatting #95

0xdevalias opened this issue Jan 1, 2024 · 5 comments · May be fixed by #105

Comments

@0xdevalias
Copy link

0xdevalias commented Jan 1, 2024

@0xdevalias
Copy link
Author

0xdevalias commented Jan 2, 2024

Benchmarking with hyperfine:

Running in the checked out directory of this repo (Ref):

⇒ npx prettier --version
3.1.1

⇒ npx biome --version
Version: 1.4.1

⇒ hyperfine --prepare 'git checkout -- unpacked/' 'npx prettier --write unpacked/' 'npx biome format --write unpacked/'
Benchmark 1: npx prettier --write unpacked/
  Time (mean ± σ):     13.243 s ±  0.675 s    [User: 21.156 s, System: 1.210 s]
  Range (min … max):   12.380 s … 14.071 s    10 runs

Benchmark 2: npx biome format --write unpacked/
  Time (mean ± σ):      1.514 s ±  0.135 s    [User: 3.343 s, System: 0.364 s]
  Range (min … max):    1.384 s …  1.775 s    10 runs

Summary
  npx biome format --write unpacked/ ran
    8.75 ± 0.90 times faster than npx prettier --write unpacked/

Config I used:

How that changed the formatted output:

  • 0xdevalias/chatgpt-source-watch@2505ac0
    • main improvements seemed to be to the indentation of nested ternaries, and some JSX blocks that previously weren't formatted
    • (note that apparently I was previously using an old 2.x version of prettier, so some of the changes shown here may have been improved/lessened if I formatted with a newer version of prettier first)

Based on the speed+formatting improvements, I ended up switching my repo over to using it:

@pionxzh
Copy link
Owner

pionxzh commented Jan 2, 2024

Thanks. I'm benchmarking and improving the performance recently. This can be a good replacement for prettier. I will test it soon.

Before switching to biome, I will have to refactor the transformation to allow async function.

Update: biome's format function is not async. There is no dependency.👍

@pionxzh
Copy link
Owner

pionxzh commented Jan 13, 2024

I just tested oxc, but it's obviously not production ready yet. Will test biome later.

@pionxzh pionxzh linked a pull request Jan 14, 2024 that will close this issue
1 task
@pionxzh
Copy link
Owner

pionxzh commented Jan 21, 2024

I'm also considering using dprint. Highly configurable. It also support adding braces, so that we can retire un-curly-braces.

@0xdevalias
Copy link
Author

0xdevalias commented Jan 22, 2024

Hadn't come across that one before; sounds interesting:

Would be interested to see how it performs speed-wise for comparable formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants