Prettier/ESLint to Biome: The Lightning-Fast Rust-Based Tool!

CoderOne
10 Dec 202311:14

Summary

TLDRこのビデオは、JavaScript用のコード整形ツールであるPrettierの代替となる新しいツールBiomeJSについて説明しています。BiomeJSはRustで書かれており、Prettierよりも大幅に高速で、フォーマッティングとリンティングの両機能を備えています。実際のベンチマークでは、BiomeJSがNextJSのリポジトリを整形する速度は、Prettierの10倍以上の速さでした。一方でPrettierチームも高速化に取り組んでおり、今後の動向が注目されます。ビデオでは、BiomeJSのセットアップ方法やVS Codeでの使用例も紹介されています。

Takeaways

  • 🛠️ prettier はコードを整形するツールですが、パフォーマンスの問題があります。
  • 💰 prettier のパフォーマンスを改善するためのバウンティキャンペーンが行われ、最終的に $22,500 の賞金が用意されました。
  • 🚀 バウンティの結果、Rust で書かれた新しいツールチェーン「biome」が誕生し、prettier よりも高速になりました。
  • ⚡ biome は prettier と eslint の機能を 1 つのツールで実現し、設定も簡単です。
  • 📈 ベンチマークでは、biome は prettier や parallel prettier よりも 5~10 倍高速であることが示されました。
  • 🌐 biome には VS Code 拡張機能があり、prettier 拡張機能と同様の体験が可能です。
  • 🔧 biome の設定は 1 つの biome.json ファイルで行われ、フォーマッターとリンターの両方を制御できます。
  • 👍 prettier チームも最近パフォーマンス改善に取り組み始めており、今後の高速化が期待されます。
  • 🤖 biome は Rust で書かれているため、マルチスレッド処理が可能で高速です。
  • 🌳 biome は開発が活発で、prettier の代替ツールとして注目を集めています。

Q & A

  • Prettierとは何ですか?

    -Prettierは、JavaScriptやTypeScriptなどのコードを自動的に整形するためのツールです。コーディングスタイルを統一し、プロジェクトのコードを整理することができます。

  • Prettierにはどのようなパフォーマンス上の問題があるのですか?

    -スクリプトによると、Prettierはパフォーマンスが遅いという問題があり、特に大規模なプロジェクトでは整形に時間がかかる傾向にあります。

  • Biome JSとは何ですか?

    -Biome JSは、Rustでゼロから書かれた新しいコード整形ツールとリンターです。Prettierに比べて大幅に高速であり、整形とリンティングの両方に対応しています。

  • なぜBiome JSがPrettierより高速なのですか?

    -Biome JSはRustで書かれているため、多スレッド処理が可能で、より高速です。さらに、単一の設定ファイルで整形とリンティングを同時に行えるため、パフォーマンスが向上しています。

  • スクリプトでBiome JSとPrettierのパフォーマンス比較はどのように行われていますか?

    -Next.jsリポジトリを使って、Biome JS、Prettier、並列化されたPrettierのパフォーマンスをベンチマークし、比較しています。Biome JSがはるかに高速であることが示されています。

  • Biome JSを導入するにはどうすればよいですか?

    -まずBiome JSをプロジェクトにインストールし、次にBiome JSONファイルを設定します。VS Codeの場合は、Biome JSの拡張機能を使うと便利です。

  • PrettierとBiome JSのリンターのパフォーマンス比較はどうでしたか?

    -単一スレッドのBiome JSはESLintより約4倍、並列化したBiome JSはESLintより約7倍高速でした。

  • Biome JSの他の利点は何ですか?

    -Biome JSは設定が簡単で、ESLintのようにたくさんのパッケージをインストールする必要がありません。つまり、導入とメンテナンスが容易です。

  • Prettierは今後のパフォーマンス改善に取り組んでいますか?

    -はい、スクリプトによると、Prettierはパフォーマンスとスピードアップのために取り組んでおり、オープンソースの専門家を雇っています。

  • プロジェクトでBiome JSかPrettierを選ぶべきでしょうか?

    -プロジェクトの規模と要件によって異なります。大規模プロジェクトや高速化が求められる場合はBiome JSが適しています。一方、小規模プロジェクトではPrettierで十分かもしれません。両者のメリット・デメリットを確認することをお勧めします。

Outlines

00:00

😃 プリティアの問題と代替ツール「Biome」の登場

プリティアはコードを整形するための優れたツールですが、パフォーマンスの問題が指摘されていました。開発者のVadim氏は、プリティアのテストケースの95%以上をクリアできるツールの開発者に対し、2万2,500ドルの賞金をかけました。この賞金に応募した結果、Rustでゼロから書かれたBiomeというツールチェーンが誕生しました。Biomeはプリティアに比べ大幅なパフォーマンス向上を実現し、賞金を獲得しました。

05:02

😄 BiomeのセットアップとVS Codeでの利用方法

BiomeはプリティアとESLintの役割を1つのツールで置き換えることができます。Biomeをプロジェクトにインストールし、biome.jsonという設定ファイルを作成することで、フォーマッターとリンターの機能を利用できます。VS Codeでは、Biomeがデフォルトのフォーマッターとしてサポートされています。ファイルを保存するだけでフォーマットが実行され、CLIからもフォーマットやリントのコマンドを実行できます。

10:03

🙂 BiomeとPrettierのベンチマーク結果

Next.jsのリポジトリを使ってBiomeとPrettierのパフォーマンスをベンチマークした結果、BiomeがPrettierを大きく上回るスピードを実現していることが分かりました。マルチスレッドのBiomeはプリティアの10倍、並列実行のPrettierよりも5倍の速さでした。リンターの機能でも、BiomeはESLintの7倍の速さを持っていました。ただし、Prettierチームもパフォーマンス改善に着手しており、今後の進化が期待されます。

Mindmap

Keywords

💡prettier

prettierは、JavaScriptなどのコードフォーマッターツールです。コードエディタで保存時やコミット前に自動整形し、コードを読みやすくきれいにします。本ビデオでは、prettierのパフォーマンス問題が指摘され、代替ツールの開発が促されています。例えば「throughout the years we've all been using prier for actually formatting our Javas scrip Json typescript react code throughout the years」と言及されています。

💡パフォーマンス

パフォーマンスとは、ソフトウェアなどの処理速度や効率のことを指します。本ビデオでは、prettierのパフォーマンスが遅いことが課題とされ、新しいツール「biome」がRust言語で書かれ、パフォーマンス向上が図られています。「so biome was completely written on run to tackle that performance issues and actually have a lot of performance benefits compared to prettier」と説明されています。

💡フォーマッター

フォーマッターは、ソースコードを整形するツールのことです。本ビデオではprettierとbiomeがフォーマッターとして紹介されています。「biome is an open- Source tool that allows you to do both formatting and linting」とあり、biomeはフォーマッターとリンター(コード規約チェッカー)の両方の機能を備えています。

💡リンター

リンターは、ソースコードが特定の規約に従っているかをチェックするツールです。本ビデオでは、biomeがリンター機能も持つことが強調されています。「biome does them both and the really nice thing and awesome part about biome that I really really love is actually it gives you everything go gives you both format and a Lin in with one two without that much of configuration」とあります。

💡マルチスレッド

マルチスレッドとは、プログラムの処理を複数のスレッドで並列実行することです。本ビデオでは、biomeがRustで書かれているためマルチスレッド処理が可能で、高速化が実現したことが説明されています。「biome of course it es R so it's like multi- threaded but of course we can actually go and use bi single threaded which going to mimic the same behavior as PR, because PR uses no GS and no GS is single threaded」とあります。

💡ベンチマーク

ベンチマークとは、ソフトウェアの性能を測定し評価することです。本ビデオでは、prettierとbiomeのパフォーマンス比較のためにベンチマークが行われています。実際にNext.jsのリポジトリで両ツールを実行し、処理時間を計測しています。「let's go ahead and actually Benchmark BM versus prer, and another plugin called prettier paraller」と言及されています。

💡rust

Rustは、システムプログラミング言語の一つで、パフォーマンス、並行性、安全性に優れています。本ビデオでは、新しいツールbiomeがRustで書かれていることが強調されており、高速化の理由となっています。「biome JS which is the new tool chain that is for lanting and formatting that was written completely from scratch on Rust」と説明があります。

💡設定

設定とは、ツールの動作をカスタマイズするための設定ファイルや項目のことです。本ビデオでは、biomeの設定ファイル「biome.json」について説明があり、フォーマットとリンターの設定を1つのファイルで管理できる利点が強調されています。「you can copy the configuration where yarn DLX BJs BM an you do in nit and this we go ahead and actually create for you this Json file for the all the configuration formatter」などの例があります。

💡VSCode拡張機能

VSCode拡張機能とは、Microsoft Visual Studio Codeに追加できるプラグインのことです。本ビデオでは、biomeのVSCode拡張機能が紹介され、prettierの代替としての利用方法が説明されています。「for those of you who already use prer in here you can just go ahead and disable prettier for me I'm going to just disable it for workspace cuz」などの例があります。

💡オープンソース

オープンソースとは、ソフトウェアのソースコードが一般に公開されていることを指します。本ビデオでは、biomeがオープンソースツールであることが強調されています。「biome is an open- Source tool that allows you to do both formatting and linting」とあり、コミュニティによる開発が期待されています。

Highlights

Prettier is a great tool for formatting code and keeping projects clean, but there are performance issues around it.

Rían Conroy (known as @ryanconroy.eth), the creator of Prettier, offered a $10,000 bounty for someone or a tool to claim and pass 95% of Prettier's test cases.

Vercel's CEO, Guillermo Rauch, matched the bounty by adding another $10,000, making it a $20,000 prize.

Other sponsors contributed to increase the total prize to $22,500.

A specific webpage was created for the bounty, submission of solutions, and for the community to compete in creating faster tools.

In the last week, bionejs, a new tool chain for linting and formatting written in Rust, was accepted as the winner for passing 95% of Prettier's test cases.

Bionejs is a single tool that replaces both Prettier (for formatting) and ESLint (for linting), with an easy setup and configuration.

Benchmarking shows that bionejs is significantly faster than Prettier, taking around 5 seconds to format the entire Next.js repository compared to Prettier's 2 seconds.

Bionejs is 5 times faster than its single-threaded version, 10 times faster than Prettier, and 7 times faster than ESLint for linting.

A VS Code extension for bionejs is available, providing the same features as the Prettier extension.

The Prettier team is taking initiatives to improve Prettier's performance by hiring Fabio, an open-source enthusiast focused on performance research.

Transcripts

play00:00

so PR is that great tool that makes our

play00:02

projects clean and tidy either when

play00:05

saving a file on your code editor or

play00:07

like before each commit your one

play00:09

prettyer to make your code formatted and

play00:11

looks clean or maybe on CI for testing

play00:14

and checking if the code is actually

play00:16

formatted the right way but have you

play00:19

ever actually thought about preter and

play00:21

the performance issues around prer so do

play00:23

you actually think that prettier is fast

play00:25

enough if you think prettier is pretty

play00:27

performance and pretty good W the cre of

play00:30

prer actually doesn't think that and

play00:32

thinks the opposite about prier that's

play00:34

actually pretty slow and in fact he put

play00:36

actually a

play00:37

$10,000 Bounty for somebody or some tool

play00:41

to claim and actually pass 95% of Pier's

play00:45

test cases there's been a huge debate

play00:47

about that and actually going forward

play00:50

guro the you know CEO Verso in here

play00:53

actually claimed and actually added

play00:55

another 10K to that so he's like

play00:57

personally matching he added another 10K

play00:59

so he be became like 20K and eventually

play01:02

a couple of other added a couple of

play01:03

boxes to reach the

play01:06

22.5k from different sponsors in here

play01:09

and matter of fact actually Alura

play01:11

created a specific web page for it for

play01:14

the Bounty and for the prices and for

play01:16

actually submitting different solutions

play01:18

from different people and that actually

play01:19

gave the community a lot of chances to

play01:21

actually win the prize and they started

play01:23

competing by creating tools thinking out

play01:25

of the box trying to make prer faster

play01:28

and so much actually happened during

play01:30

those days but eventually we have a

play01:33

winner technically in the last week

play01:35

biome if you just scroll a little bit

play01:36

down in here so the solutions that were

play01:38

accepted is biome JS which is the new

play01:41

tool chain that is for lanting and

play01:42

formatting that was written completely

play01:45

from scratch on Rust and it makes huge

play01:47

difference when it comes to Performance

play01:49

compared to prettier and yes it passed

play01:51

the 95% test cases that were sent by

play01:54

prier so throughout the years we've all

play01:57

been using prier for actually formatting

play01:59

our Javas scrip Json typescript react

play02:02

code throughout the years and it's been

play02:04

great so far had so many features so

play02:06

much support by the community and

play02:08

everything actually has one issue as any

play02:10

other JS tool JS Library which is

play02:13

performance so biome was completely

play02:15

written on run to tackle that

play02:17

performance issues and actually have a

play02:19

lot of performance benefits compared to

play02:21

prettier and to see the actual prettier

play02:23

case study in here I'm going to go ahead

play02:24

and run a quick command in here which

play02:26

you can actually use prier to format and

play02:28

actually fix any formatting issues on

play02:31

the weback reposter you see in here

play02:33

we've got the weback repo which is

play02:35

cloned from GitHub the whole open source

play02:38

repos 3 with everything so I'm just

play02:40

going to go ahead and tell they to go

play02:41

ahead and look for any JavaScript files

play02:43

out of that repo and actually format it

play02:45

using pretty I'm going to see how fast

play02:47

it's going to do so there you go we're

play02:49

going to run the benchmarking here of

play02:50

course I'm going to use hyperon which is

play02:52

a really cool tool for benchmarking and

play02:54

it's going to run that a couple of times

play02:55

to get a median time and there you go so

play02:58

the mean time in here for actually using

play03:01

prettier to format and actually fix any

play03:03

issues inside of the whole weback

play03:05

repository for all the JavaScript files

play03:07

inside of that one it took around 2

play03:09

seconds which it might seem a little

play03:11

slow but it actually is not in the word

play03:13

of JavaScript and web development

play03:16

anything more than 1 second is quite a

play03:18

lot while in the other hand if you look

play03:20

into biome biome is an open- Source tool

play03:23

that allows you to do both formatting

play03:25

and linting which means you're going to

play03:27

replace both prettier or like or normal

play03:30

format that you can actually use and

play03:31

it's going to replace something like es

play03:33

lint which is a linter with one single

play03:36

tool and biome does them both and the

play03:38

really nice thing and awesome part about

play03:40

biome that I really really love is

play03:42

actually it gives you everything go

play03:44

gives you both format and a Lin in with

play03:46

one two without that much of

play03:48

configuration you don't need to install

play03:50

like hundreds of packages to get es lint

play03:52

working with typc and stuff like that

play03:54

everything works out of the box

play03:56

everything is easy to set up and most

play03:57

importantly it's not going to you or

play03:59

make you insane to set up the tool and

play04:01

start actually formatting and Lin in

play04:03

your project so if you get started in

play04:04

here you're going to find the

play04:05

installation in here of course you can

play04:06

go and install it using any package

play04:08

manager in here mpm and everything and

play04:10

the configuration itself you can use the

play04:12

CLI is going to put biome dojon which is

play04:15

the main file that's going to hold all

play04:17

the configuration both the scre here for

play04:19

linter and for the formatter as well and

play04:22

for the usage you simply just go ahead

play04:23

and do MPX or you can just use yourn

play04:26

volume in here you do volume formats you

play04:28

give you the files all whole project and

play04:30

you do it dash dash right to go ahead

play04:32

and fix any issues and write them to the

play04:34

files the same thing goes for the link

play04:36

in here we just use Link we give it the

play04:38

files and it's going to give us a really

play04:40

nice colored and very straightforward

play04:43

output or you can also use checkin here

play04:45

which most of the time is going to be

play04:46

used for the CI that's going to do

play04:48

formatting and Linkin files and it's

play04:50

going to organize the import for you and

play04:52

for all the vs code lers out there biome

play04:54

is available as a V Code extension

play04:56

that's going to actually give you the

play04:57

all superpowers that you were used to

play04:59

have have and get by using the prettyer

play05:01

extension as well so for example I have

play05:03

my portfolio projects in here and for

play05:05

example let's say we're going to go

play05:06

ahead and migrate from prettyer into BJs

play05:09

so here first thing of course you do

play05:10

just go ahead and install BJs in here

play05:12

make sure to install the binary locally

play05:15

and not globally because globally is

play05:16

going to cause a lot of issues it's

play05:18

you're going to have like version

play05:19

inconsistencies and a lot a lot of

play05:21

problems so make sure for every single

play05:22

project you install bu them locally for

play05:25

each projects inside of the node modes

play05:26

of each projects in here the next thing

play05:28

you want to do is actually stop the

play05:29

configuration so you can copy the

play05:31

configuration where yarn DLX BJs BM and

play05:34

you do in nit and this we go ahead and

play05:36

actually create for you this Json file

play05:39

for the all the configuration formatter

play05:41

of course you're going to use this for

play05:42

formatting as well and for the liner as

play05:44

well all the rules all the configuration

play05:46

is going to be in one single place now

play05:48

to use the prettier vs code extension

play05:50

properly just go ahead and install the

play05:52

extension in here and of course for

play05:54

those of you who already use prer in

play05:55

here you can just go ahead and disable

play05:57

prettier for me I'm going to just

play05:58

disable it for workspace cuz I'm not

play06:00

willing to disable it for everything a

play06:01

lot of project are actually using pretty

play06:03

right now and after reloading in here

play06:05

you go back to any file in here for

play06:06

example you can do the command pallet

play06:08

you choose format documents and it's

play06:10

going to prompt you that oh you don't

play06:11

have a default format a setup you can go

play06:13

ahead and put a one in here you can do

play06:14

configure and you can go ahead from the

play06:16

top choose biome so you do biome JS

play06:19

biome you click on that one and now you

play06:21

clearly here down here you can see biome

play06:23

as our form matter if you click this

play06:25

actually going to use biome for example

play06:27

I can do indentation in here I can close

play06:29

and actually going to put everything for

play06:30

me in here as I need it uh for example

play06:33

you can just you know add that for

play06:34

example you can click ahead and save and

play06:35

the format is going to happen

play06:37

immediately so as simple as that you can

play06:39

just go and set up biome and of course

play06:40

the configuration that's going to

play06:42

actually rely on and use is the

play06:44

configuration that you're have in here

play06:45

inside of the biome Json so for example

play06:47

I have like white line width in here to

play06:49

be 80 indent style want it to be space

play06:51

for example for JavaScript I want to use

play06:53

the format for like the quot I want to

play06:55

use only single quotation and I only

play06:57

want to use the trailing Comm and for ES

play06:59

five formatting and inside of the

play07:01

package.json in here I can go ahead and

play07:03

add a new one let do like for example

play07:05

biome uh check for example in here and

play07:08

it can just go ahead and use volume and

play07:11

it can just go ahead and do check and

play07:13

make sure you choose the the fold that

play07:14

you want to actually Linton format which

play07:16

for our case is the SRC and here after

play07:18

you run the check you're going to find

play07:20

all the issues for example it's telling

play07:21

you oh you can't use this function use

play07:23

this typescript and it's going to do all

play07:25

the linin in the word for you as C in

play07:27

here it gives you like oh we found five

play07:29

errors and checked 149 files in 19

play07:33

millisecond all right so let's go ahead

play07:35

and actually Benchmark BM versus prer

play07:38

and another plugin called prettier

play07:40

paraller which actually uses multi

play07:43

threaded prer and actually runs them

play07:44

concurrently to get a faster formatting

play07:48

so here we have actually a file I

play07:49

actually clone the whole BJs repost from

play07:53

GitHub which has a benchmark folder in

play07:54

here and actually has a really nice

play07:56

script in here that actually allows you

play07:57

to Benchmark and customize it however

play07:59

you you want so here iscl you can like

play08:01

specify for the format or different

play08:02

reposters you can use whether you want

play08:04

to use like web pack reposter in here

play08:06

for Benchmark here or not I've commented

play08:08

that code by the way and I've actually

play08:10

added specifically next juice in here

play08:12

because it's a very gigantic reposter

play08:14

has a lot of jobs crep on typ code and

play08:16

especially for the packages in here has

play08:18

a lot of packages like if you look at

play08:20

the repository in here has a tremendous

play08:21

amount of packages in here inside of the

play08:23

packages folder with next next s swc MDX

play08:27

so much so I'm going to go and actually

play08:28

benchmark all the prettier prettier

play08:30

parallel and biome js on the next GS

play08:33

reposter in here and see which one is

play08:35

actually faster now of course bi is

play08:37

actually claiming to be 25 faster than

play08:40

prier 20 times faster than parallel prer

play08:43

and like around two times faster than

play08:45

dprint and by the way for those of you

play08:47

who doesn't know about dprint dprint is

play08:49

another rust base format that is

play08:51

actually pretty basic compared to prer

play08:53

but it's actually still pretty fast so

play08:55

simply here I'm going to use node to

play08:56

actually run our scripts in here of

play08:58

course here is going to actually build

play08:59

biome from source and actually start

play09:02

ascl in here is actually benchmarking

play09:03

you know examples of like nextjs and the

play09:06

nextjs packages and everything and there

play09:08

you go we have the results so for Bome

play09:10

in here finished like in 5 seconds and

play09:12

he finished whole next gson with all the

play09:14

packages are inside examples and

play09:16

benchmarks and everything so it's like

play09:18

in only 5 seconds in here this is like

play09:20

the mean time for biome and biome

play09:23

actually run five times faster than the

play09:26

biome single threaded because biome of

play09:28

course it es R so it's like multi-

play09:30

threaded but of course we can actually

play09:31

go and use bi single threaded which

play09:34

going to mimic the same behavior as PR

play09:36

because PR uses no GS and no GS is

play09:38

single threaded so you got the point so

play09:41

it's still like Bome normally the mild

play09:43

thread version is like five times faster

play09:44

than single threaded version and it's

play09:47

like 563 which isn't like too much of a

play09:50

difference between the single threaded

play09:52

and the parallel puor in here which

play09:53

actually uses concurrent threads to run

play09:56

that one so that's actually pretty good

play09:57

but compared to pretor itself is

play10:00

actually like 10 times faster which is

play10:02

crazy compared to like you know we've

play10:04

gotten here the whole next us repository

play10:06

which is a huge repository now in the

play10:08

other hand in here we did actually go

play10:10

ahead and run the linter as well so I

play10:11

actually go ahead and Benchmark bu

play10:14

linter with es to see how fast it is so

play10:17

for example you see Benchmark one es

play10:19

Benchmark 2 biome in here and bium

play10:21

single threaded and in summary in here

play10:24

you can clearly see that volum run like

play10:27

4.3 times faster than biome single

play10:29

threaded and seven times faster than

play10:32

normal es slint so still biome is

play10:34

beating both prer and Es slint at every

play10:38

aspect even single threaded but hey

play10:40

likely for us PR's actually taking an

play10:42

initiative to go ahead and speed up and

play10:44

make PR your Faster by actually hiring

play10:47

Fabio who's like an open source

play10:49

Enthusiast about performance and

play10:50

everything and he's actually doing some

play10:52

researches and he put this really nice

play10:54

block Post in here that explains how per

play10:56

Works what are you know the the

play10:58

approaches make prettier faster so this

play11:01

is a really good initiative and I'm

play11:03

pretty sure prer is going to become a

play11:05

lot faster in the near future so I'm I'm

play11:07

really looking forward to that but

play11:09

anyway guys thanks you for watching hope

play11:10

you guys enjoyed and catch you hopefully

play11:12

in the next ones

Rate This

5.0 / 5 (0 votes)

Related Tags
コード整形パフォーマンスRustオープンソースプログラミングJavaScriptTypeScriptWeb開発フロントエンドツール比較
Do you need a summary in English?