Why is Bun fast?
... Zig's low-level control over memory and lack of hidden control flow makes it much simpler to write fast software. ...
Is your sense also that this is the root cause of Bun's outstanding speed? Node.js is written in C++ (although not primarily) which also requires low-level control over memory.Is there something about C++ that makes it less well-suited than Zig for what Bun does?
Or is the problem with Node.js that it relies too much on JavaScript rather than C++ in hot paths?[2]
[1] https://bun.sh/
https://medium.com/deno-the-complete-reference/node-js-vs-de...
1) That benchmark appears to be bottlenecked by the HTTP client — that’s why the numbers are so close for each runtime. Effectively, it is benchmarking the http client and not the http server.
The benchmarking tool has to be at least as fast the server and it needs to support HTTP keep alive. That means popular Node.js-based benchmarking tools like autocannon don’t produce useful results in benchmarks like these
Instead, a tool like oha or wrk or bombardier is better
2) That benchmark is not using the ReactDOM server build for Bun's runtime, which is used in Bun's benchmark and is part of the next release of react-dom.
PR: https://github.com/facebook/react/pull/25597#issuecomment-13...
Source of Bun's homepage benchmark: https://github.com/oven-sh/bun/blob/9ef33312b1b199931c29c182...
How are you funded? Is speed enough of a concern to take a risk on using this vs Node ? From my experience with Node your lucky if it works at all, I don't know if I'd like to add another variable when things go wrong.
I can't imagine this supporting every single npm module.
That said, god speed. If you can really make JavaScript fast as a complied language, I and many other JS devs will be happy.
I feel like compatibility-wise both projects are mostly there already
Missing some of the other general purpose use cases that devs would want to build - which wouldn't fit into bun's flavor of hosting.
Getting early funding is cool , but I'm not sold on the business model. Tons of hosting providers exist, corps are unlikely to switch meaning your stuck selling to hobbyist / small developers.
That said, they just need to stay alive until aquired
Different strokes for different folks
Some people really enjoy working. I know, it's hard to believe :)
I've worked with hundreds of scientists from different domains over the past two decades and I've literally never once heard of wanting to use Javascript for anything remotely scientific.
Furthermore, given that WebAssembly seems poised to (eventually) make strides in how browser-oriented applications are built then the logical conclusion is a sort of reduce function on languages where you choose the language that's the most pleasant to write and maintain since you will eventually be able to just target the browser from anything. For the life of me, I can't see a future where large, STEM-educated groups and agencies decide "Well yeah, I guess if we can use this cooked-in-a-weekend piece of $^&# then why would we ever use Python?"
I think a lot of language enthusiasts see python projects entering into spaces where it wasn't previously viable and think that the same principle applies to their language, which misses something fundamental about why Python has so deeply entrenched itself into the STEM/ML world, and why it will NEVER be uprooted. When I see things like Brython/Pyscript/Pyodide, it's obvious to me that people would rather write Python for ~accomplishing the task they set out to~ than have to muck around with another language entirely. Python is a winner in so many spaces because of that element of taking the programmer from Point A to Point B the easiest way. It's a language designed for accomplishing tasks, for getting stuff done, for being understood at a glance. Javascript was made up by one guy, in a very short period of time, for a singular purpose that it didn't even do well when it was introduced and has stuck around due to sheer coincidence and convenience. All languages on a long enough timescale converge to a point of usefulness but if we're pitting Python against JS I just can't see the scales tipping enough to warrant choosing it for real work.
The thing is a lot of scientists are going to have to learn FE technologies eventually. The push to make scientific work more presentable and accessible means JS' place in academia is cemented for a long time.
WebAssembly is still a long way off and given that even Rust WASM was found to usually do worse than JS, I highly doubt Python WASM will outperform it any time soon. Even once it does become worth it, tooling has a long ways to go
> people would rather write Python for ~accomplishing the task they set out to~ than have to muck around with another language entirely.
your argument seems to boil down to: people know Python so they wanna use Python. People can just as easily know JS/TS. If I'm a botanist and I really don't wanna invest too much of my time in learning languages I can choose between Python, the language with all the scientific libraries, and JavaScript, the language of the web. If I choose the former, I'll likely have to bother someone to help me present my work to the web anyways. If in the near future JS also reaches good support for scientific/ml libraries it seems like entering that ecosystem is an obvious advantage. I get to learn the web and access scientific libraries at the same time
Also I don't really find Python all that legible. The language you're describing isn't Python nor JavaScript. It's something like Ruby. Modern javascript has some obvious advantages when it comes to syntactic sugar like arrow functions. It's also easier to teach because you don't need to install anything. Just open up your html file in any browser
I can see the validity of such an argument for languages like R or Matlab or Julia (EDIT: or Fortran), wherein the languages were designed with scientific use cases in mind. Python is not in that category; it's rather in the category of Perl (EDIT: and not Fortran): languages that happened to be useful to scientists by happenstance, and around which a library ecosystem developed in support of that usefulness. No fundamental reason why Javascript would somehow be ineligible if Python is eligible.
Instead of using a wasm runtime for python for that it might also make more sense performance-wise to at least write that part in js if not an even faster language compiled to wasm. Either way if it ends up on a webpage some js will be needed to at least glue things together.
Also, from the perspective of just wanting to write some code and get what I want, I really don't see much of a difference between python and js.
For the rest of us, it's kinda the other way around. We can't figure out why scientists prefer python over all the other many options. I'm assuming it's just a lot of cobbled together legacy code nobody wants to breathe on.
> Furthermore, given that WebAssembly seems poised to (eventually) make strides in how browser-oriented applications are built
Also, this isn't really true. The proposals and implementations out there suggest the goal is to use wasm for libraries and specialized optimizations. Nobody wants to wait for a massive binary to download. You can try to port legacy junk apps, but making it usable on the web (not a canvas) might turn out to be more work than it's worth in many cases.
In the same way that Python developers are interested in extending their ecosystem to other spaces, JavaScript developers are interested in growing into the data science space. But that doesn't happen unless there's a clear benefit for switching.
What advantages do a native JS solution have over Python? Performance: There are arguably many more developers and companies focused on pure JS performance than python. Community: A JS solution opens up a much larger pool of talent to build innovative solutions. Cost: Running heavy computations client-side, in the web browser, reduces costs for service providers.
PS: We're hiring for this and other related problems https://sheetjs.com/careers
I’ve got honestly no idea how long it took to write the first ‘version’ of the Python interpreter or whatever. It’s not as much a piece of tech lore that was later (mis)appropriated for Internet arguments. Even after acknowledging that JS being a browser-based language causes let’s say ‘less well-considered’ language quirks to hang around for longer than we’d like, I’d never use that as such a central argument.
To be clear: in my day job I predominantly write Python. It’s a web project, which I have control over the architecture of, and it’s for the most part oldschool server-side rendered Django views, in no small part because JavaScript scares me. I am FAR from a fanboy. Having recently spent a solid month writing TypeScript - which for contexts like this should be considered ‘JavaScript’ - it’s (way too late) become clear to me that it’s a language worthy of respect and consideration.
If we want to get into the comparative qualities of JS you dislike, well, I still don’t think I’d be interested in a language wars back and forth. However at least we’d be getting closer to a productive conversation. And, to be clear, I’m not jumping to take up arms arguing that JavaScript is as suitable for ML/scientific computing as Python is. Even if we pretend that e.g. pandas and numpy were available for JS, I’m still not confident that JS is up to the task, but I also don’t feel confident arguing against it either.
What I will say is that, coming back to writing Python after being deep in JS for just a little while, there are JS language features that I felt myself missing. Just like there are Python language features I felt myself missing in JS. My point is, again, that modern JS is in my eyes within the realm of respectable general purpose language, ESPECIALLY with TS.
Let's say you want to a small notebook in the browser, JavaScript is nicer there, even with WebAssembly. Or the user is not a scientist, and already knows JS, and it lets them discover ML. It's not taking anything away from those Python projects.
A scientist that doesn't want to give whoever is responsible for deploying their software a massive headache and ops problems.
One who has a reason to?
All languages have their strengths and weaknesses. Popular languages have a positive balance. JS is great for the web, and there's surely >0 applications in science that require web interoperability...
The statement "mucking around with learning another language entirely", comes across as someone who hasn't experienced other languages to the point they see they often have more similarities than differences, become easier and easier to learn as a result, and are best used - at that point - like a box of tools, rather than the situation most programmers start with of using a screwdriver for everything because it's all they have.
This is where more than a few scientists seem to have got stuck with Python, and possibly part of why the language itself has accelerated into becoming a bit of a mess - though they often do, anyway. (So much for that "just getting from A to B" thing, I hope it sticks around, but it's not looking good.)
While many might not presently be in a position to, any scientist who could choose to use something more readily suited to a particular use-case, such as JS, or C, or Perl/Ruby, or Elixir (particularly with regard to ML lately), may find themselves reaching higher heights than they could have when limited to only Python.
As with anything, those with more options have an edge over those with fewer.
But the scientific strength of "Python" comes not from Python itself. It just offers a nice interface to tons of C, C++, and Fortran code that implement the core of numpy, pandas, keras, pytorch, etc. That's what STEM and ML crowds use. Moving that code to WASM must be possible, but likely for demo purposes, not for serious work.
I'm curious to hear your thoughts about Bun/Civet integration to explore improvements to the language frontend as well as the language backend?
1) using JavaScriptCore instead of V8
2) porting esbuild from Go to Zig
I have a couple of questions about (2):
1. How long did it take you to port esbuild?
2. Why did you choose to port esbuild to Zig instead of another language e.g. V?
He chose Zig because it's a good language for performance sensitive applications and found himself to be very productive in it.
And thanks for bun! It's been impressive and inspiring to watch.
For now you can do
bunx bun-repl- zig.news has some good posts https://zig.news/
- Zig's language docs: https://ziglang.org/documentation/master/
- Zig's standard library code https://github.com/ziglang/zig/
I mean, I wish bun all the best, but trying to wrap my head around - who the heck and on what basis gave to bun project a money :-)
Tracking issue: https://github.com/oven-sh/bun/issues/1822
If you're familiar with Node, Bun should feel familiar except you don't need as much tooling to use it.
Things like TypeScript, jsx, loading .env files, Jest-like test runner etc just work. You can use the builtin TypeScript/JS LSP in your text editor instead of installing a separate extension. You can import packages from npm without the "npm:" specifier. It's worth mentioning that Bun doesn't support HTTPS imports yet, so you'll need to use npm - but bun has a very fast builtin npm client. Like deno, you can often skip running `bun install` or `npm install` entirely for bun because bun will automatically install dependencies from npm when there is no node_modules folder
Incidentally, what's up with the resistance against this from the standards maintainers? [1]
The request exists since 2017, there are tons of use cases and developer interest, but Chrome refuses implementation on technicalities. What gives?
IMO this sounds like a YAGNI thing. You can pass extra information via the URL, query parameters, cookies work just like normal HTTP, etc... And if those options don't work you can just exchange whatever information you want inside the websocket connection. I can't think of a use case that requires a custom header.
Would leveraging `async_hooks` be possible in the future with the used non-v8 engine or would there be some alternative?
We’ll likely do AsyncLocalStorage and make the rest of async_hooks a no-op. async_hooks are detrimental to event loop performance, but important for observability tooling. I think a better approach here is designing a more specific API for the top usecases
Really appreciate the pragmatic approach!
(Instead of being dogmatic like "we just can't/won't deliver async_hooks unless its exactly right", so then it never happens.)
Is Bun ready to be used for production projects?
https://github.com/oven-sh/bun/releases/expanded_assets/bun-...
it's worth revisiting though since its been a little while
If bun can crack executable generation (along with code signing and notarization), it’ll unlock a whole new dimension for bun apps.
Why would anybody not use Bun, other than the cost of migration, given the performance improvement?
Nevertheless, amazing performance. Feels refreshing to see more improvements to the JS/TS community.
Most of Bun is written in native code (zig) rather than JavaScript. We leverage modern CPU features like SIMD, closely watch syscall overhead and spend a lot of time reading about system calls and platform-specific system APIs
Bun is still pretty early - we are not at 1.0 yet. There are crashes and many bugs to fix, but we are making steady progress towards a stable release
However, it's worth noting that those benchmarks have been critized a lot for being cherry-picked and not very representative of real-world use-cases
I've tried to look it up a number of times but I've yet to come across any benchmarks done by an independent party (please share if you find some)
But I have worked _with_ node for a very long time, and I am intensely familiar with the JS ecosystem's "flavour of the day" culture.
I think people are rightfully suspicious of such bold claims. Particularly as Deno came out to much fanfare and self promotion but like...I barely hear of anyone actually using it in production as opposed to node.
Not saying that node will be King forever, just that I'm taking a grain of salt.
It's probably a decent tradeoff in a lot of applications, but probably not in all of them.
Bun isn't scheduling the garbage collector between microtask ticks and we might need to start doing that to reduce memory usage. We did that in Bun v0.3 for the event loop, but we didn't do it for the microtask queue.
But you bring up a good point and I'd like to see a more holistic benchmark that takes both space and time complexity into account (preferably done by an independent party)
From another comment:
Reasons not to use bun:
- it is pre v1, so unstable API
- it is unstable, so you will deal with crashes
- newer, so help articles will be hard to find
You're thinking of the io.js debacle
i mean, i don’t know how many people even use deno, let alone bun.
Bun is not a JavaScript bundler, it’s a JavaScript runtime, like NodeJS or Firefox.
You can (could, theoretically) run webpack with bun instead of node
Bun uses JavaScriptCore from WebKit/Safari, similar to how Node uses V8 from Chrome
I mean he's a Thiel Fellow, which should give you an idea of what I'm talking about.