スクリプト全文 (英日対訳)

104

It is September 8th, 2023, and you are watching The Code Report.

2023年9月8日、The Code Reportをご覧いただいています。

Yesterday was a huge day for soy devs.

昨日は開発者にとって大きな日でした。

Mojo became generally available, a super set of Python that's up to 35,000 times faster.

Pythonの上位互換で最大35,000倍高速なMojoが一般公開されました。

But JavaScript also got way faster, thanks to a new Swiss Army knife called BUN,

でもJavaScriptも、万能ツールBUNのおかげで格段に速くなりました。

and that means it's time for some new stickers on my MacBook Pro.

つまりMacBook Proに新しいステッカーを貼る時が来たということです。

JavaScript developers have grown tired of reinventing new frameworks,

JavaScript開発者は新しいフレームワークを作り続けることに飽きてきて、

so now we're building entirely new JavaScript runtimes.

今では全く新しいJavaScriptランタイムを作るようになりました。

In the beginning, we had Node.js, then rearranged the letters to make Dino,

最初にNode.jsがあり、文字を並べ替えてDenoが生まれ、

and now we've got BUN fresh out of the oven,

そして今、焼き立てのBUNが登場しました。

which just hit 1.0 this morning.

今朝ちょうどバージョン1.0に到達したところです。

And you should take notice, because it can run your JavaScript code faster than any other tool known to man.

これは注目すべきで、今知られているどんなツールよりも速くJavaScriptコードを実行できます。

But not just that, it also acts as a bundler like Webpack or Veet,

それだけでなく、WebpackやViteのようなバンドラーとしても機能し、

a test runner like Jest or Karma,

JestやKarmaのようなテストランナーとしても、

and a package manager like NPM or Yarn.

NPMやYarnのようなパッケージマネージャーとしても使えます。

In addition, it's almost fully compatible with existing Node.js APIs,

さらに、既存のNode.js APIともほぼ完全に互換性があり、

but has its own set of highly optimized APIs

独自に高度最適化されたAPI群も備えています。

that actually make it fun to build high-performance server-side applications with JavaScript.

これにより、JavaScriptで高性能なサーバーサイドアプリを作るのが本当に楽しくなります。

Before we get into it though, I want to show you another awesome new tool from our sponsor, DevGPT.

本題に入る前に、スポンサーDevGPTの素晴らしい新ツールを紹介させてください。

By now you've heard of tools like ChatGPT and Copilot,

ChatGPTやCopilotのようなツールはもうご存知だと思いますが、

but DevGPT takes AI code generation to the next level by integrating directly with your Git repo,

DevGPTはGitリポジトリと直接連携することで、AIコード生成を次のレベルへ引き上げます。

giving the AI the full context of your tech stack and project.

AIにあなたの技術スタックとプロジェクトの全体像を与えてくれるんです。

After writing a prompt to fix a bug or create a feature,

バグ修正や機能追加のプロンプトを書くと、

it'll ask follow-up questions to write highly targeted and useful code.

的確で役立つコードを書くために追加の質問をしてくれます。

Once the code is generated, you can then sync those changes to your local project instantly.

コードが生成されたら、その変更を即座にローカルプロジェクトへ同期できます。

Then you could prompt it to generate some unit tests to validate that code.

そのコードを検証するためのユニットテストを生成させることもできます。

It's like having an automated engineer by your side,

まるで自動化されたエンジニアが隣にいるようなもので、

who can take care of your GitHub issues and Jira tickets instantly without complaining.

文句ひとつ言わずにGitHub issueやJiraチケットを瞬時に片付けてくれます。

You can try it out for free yourself right now with the link below.

下のリンクから今すぐ無料で試せます。

But now let's get back to Bun.

では、Bunの話に戻りましょう。

First of all, how do they make this thing so fast?

まず、どうやってこれをこんなに速くしているのでしょうか。

One major difference compared to Node and Dino,

NodeやDenoとの大きな違いのひとつは、

which uses the V8 engine from Chrome,

それらがChrome製のV8エンジンを使っているのに対し、

Bun uses JavaScript Core from Safari,

BunはSafari製のJavaScriptCoreを使っている点です。

which is known to be optimized for faster startup times.

これは起動時間の速さに最適化されていることで知られています。

In addition, Bun is implemented in the Zig programming language.

さらに、BunはZigというプログラミング言語で実装されています。

They've put a focus on profile and performance bottlenecks

プロファイリングとパフォーマンスのボトルネックに重点を置き、

and implement APIs in native code.

APIをネイティブコードで実装しています。

The end result is a hello world with TypeScript that's five times faster than ES build.

その結果、TypeScriptのHello WorldがESbuildより5倍速くなりました。

Keep in mind though, benchmarks can always be cherry-picked

とはいえ、ベンチマークは都合よく選ばれがちで、

and rarely reflect real-world performance.

実際のパフォーマンスを反映していないことも多い点は覚えておいてください。

It's fun to go fast,

速いのは楽しいものですが、

but because I only have 12 monthly active users on my website,

自分のサイトの月間アクティブユーザーはたった12人なので、

it doesn't make a huge difference for me.

自分にとってはそれほど大きな違いにはなりません。

What I care about is the developer experience.

私が気にしているのは開発者体験です。

Can Bun make my life easier?

Bunは私の生活を楽にしてくれるのか。

Well first up, it's got awesome TypeScript support out of the box.

まず、標準で素晴らしいTypeScriptサポートを備えています。

You can immediately start writing TypeScript code without any configuration or headaches.

設定の面倒もなく、すぐにTypeScriptコードを書き始められます。

And it also supports JSX and hot reloading,

JSXやホットリロードにも対応しているので、

which means you don't need any weird dependencies like Node.mon and concurrently

nodemonやconcurrentlyのような妙な依存パッケージは不要です。

to recompile your code when things change.

変更があった時にコードを再コンパイルするためのものが、です。

That's cool, but one of the absolute worst things about Node

それも良いのですが、Nodeの最悪な点のひとつと言えば、

has been the transition from common JS to ES modules.

CommonJSからESモジュールへの移行でした。

What's cool about Bun is that you can just use import and require in the same file

Bunの良いところは、同じファイル内でimportとrequireを両方使えて、

and everything just magically works.

それが魔法のようにちゃんと動くことです。

And it's compatible with existing Node.js packages,

既存のNode.jsパッケージとも互換性があるので、

which means you don't have to reinvent the wheel

車輪の再発明をする必要がありません。

for every little thing you want to implement.

ちょっとした機能を実装するたびに、です。

Dino also added NPM support as well recently,

Denoも最近NPMサポートを追加しましたが、

but what I really like about Bun is its native APIs.

Bunで本当に気に入っているのはそのネイティブAPIです。

For example, to read and write to the file system,

例えば、ファイルシステムへの読み書きは、

we can access the global Bun runtime and make a reference to a file,

グローバルなBunランタイムにアクセスしてファイルへの参照を作り、

then lazily read it or parse its JSON.

遅延読み込みしたりJSONとしてパースしたりできます。

That may not seem like a big deal, but in Node.js,

大したことに見えないかもしれませんが、Node.jsでは

there are three different ways to do the same thing.

同じことをするのに3通りもの方法があります。

Read file with callbacks, read file with promises, or read file sync.

コールバックで読む、Promiseで読む、または同期的に読む、です。

You can actually use all of those in Bun,

実はBunでもそれら全部を使えるのですが、

but not only are the native APIs faster, they're easier to use.

ネイティブAPIは速いだけでなく、使いやすくもあります。

In addition, it's extremely easy to set up an HTTP server in Bun

さらに、BunでHTTPサーバーを立てるのも非常に簡単で、

by simply calling the serve method.

serveメソッドを呼ぶだけで済みます。

You then use familiar browser primitives like fetch and response

その後は、fetchやResponseなどおなじみのブラウザの機能を使って

to build your API.

APIを構築していきます。

That'll take you pretty far,

これだけでもかなり遠くまで行けますが、

but there's also frameworks that work with Bun like Elysia

BunにはElysiaのようなフレームワークもあり、

that claims to be 18 times faster than Express.js in Node.

NodeのExpress.jsより18倍速いと謳っています。

Bun also works with Hano,

BunはHonoとも組み合わせて使えます。

which has been my go-to framework for building APIs recently.

最近、私がAPI構築で愛用しているフレームワークです。

Bun has tons of other simplifications as well,

Bunには他にもたくさんの簡略化があり、

like it makes WebSockets nice and simple out of the box

標準でWebSocketをシンプルかつ簡単に扱えたり、

without any extra dependencies,

余計な依存パッケージなしで、

and you can use environment variables without things like .env.

.envのようなものがなくても環境変数を使えたりします。

Pretty cool, but as the name implies, Bun is also a bundler.

かなり良い機能ですが、名前が示す通りBunはバンドラーでもあります。

The Bun build command will take all your source files

bun buildコマンドはすべてのソースファイルを取り込んで、

and then combine them into a single output

1つの出力にまとめてくれます。

that can be used in a browser.

それはブラウザで使える形式です。

And based on this benchmark,

そしてこのベンチマークを見ると、

it's pretty amazing how much faster things have gotten

どれだけ速くなったかが驚くほどわかります。

just since Webpack 5 a couple years ago.

数年前のWebpack 5の頃と比べても、です。

Oh, and another really cool thing is that Bun

ああ、もうひとつ本当にすごいのは、Bunには

has a SQL-like database built directly into the runtime.

SQLライクなデータベースがランタイムに直接組み込まれていることです。

It's incredibly convenient to have a relational database

リレーショナルデータベースが最初から使えるのは非常に便利で、

without the need to install and configure a bunch of drivers.

大量のドライバーをインストールして設定する必要がありません。

Another thing we need to talk about though

もうひとつ触れておくべきなのが、

is the Bun package manager.

Bunのパッケージマネージャーです。

That's up to 25 times faster than NPM,

NPMより最大25倍速く、

and it's actually a standalone tool

実は単体で動くツールでもあるので、

that can be used in any Node.js project today.

今すぐどんなNode.jsプロジェクトでも使えます。

If you want to make things go faster right now,

今すぐ何かを速くしたいなら、

replace npx with a command like bunks cowsay hello world,

npxをbunx cowsay hello worldのようなコマンドに置き換えてみてください。

which allows you to save a few precious milliseconds

貴重な数ミリ秒を節約できます。

when saying hi to your mom,

お母さんに挨拶する時のような場面で、です。

which is important because you never know

これは大事なことです、なぜなら誰にもわからないからです。

how much time you have left to do that.

それをする時間があとどれくらい残っているかは。

This has been the code report.

以上、The Code Reportでした。

Thanks for watching, and I will see you in the next one.

ご視聴ありがとうございました、また次回お会いしましょう。