1BRC in Node.js 23 Sec and in Bun 14 Sec (but there is a catch with the latter 😁) #256
Edgar-P-yan
started this conversation in
Show and tell
Replies: 1 comment
-
I was also considering to use mmap, but node.js does not provide any builtin API for that. There are some third party native addons that provide mmap support, but the purpose of this challenge is rather to optimize the JS code itself. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Repositories
The old repo for both Node.js and Bun that I created in my own account: https://github.com/Edgar-P-yan/1brc-nodejs-bunUPDATE: The new and active repositories that I created in the @1brc organization, and where you can submit your own solutions:
Straight to the code:
🐢 Nodejs version.
🍞 Bun version.
Details:
parseFloat
,parseInt
andNumer()
).What should be improved:
Map
, which is too general purpose for this task, hence quite slow, around 30% of spent time is on the Map.Problems with Bun
I noted that it "potentially" runs in 14s. The problem with Bun is that i caught a bug (I reported it here) where i couldnt read the file at a random position if that random position is greater than around 65k (the size of the buffer). But a tenth of the
measurements.txt
file got processed in 13s on just one core, so if Bun fixes it's seek-and-read feature then on my 10 core machine it'll probably fit in 14s range accounting for the final results formation, thus being faster by 40% then nodejs.Try out:
# First generate the 13GB `measurements.txt` file. For this step you'll need the Java installed: ./create_measurements.sh 1000000000
# Node.js 23s on my machine: sh calculate_average_Edgar-P-Yan_nodejs.sh measurements.txt
# Bun, for now only single threaded due to the bug in Bun's stdlib, so takes around 120s on my machine: sh calculate_average_Edgar-P-Yan_bun.sh measurements.txt
Beta Was this translation helpful? Give feedback.
All reactions