buffer: use fast API for writing one-byte strings#54311
buffer: use fast API for writing one-byte strings#54311nodejs-github-bot merged 1 commit intonodejs:mainfrom
Conversation
|
Probably because the benchmark has a flaw, and the input is not a one byte string. I recommend reading this amazing blog post: https://iliazeus.github.io/articles/js-string-optimizations-en/ |
|
@anonrig still only minimal difference: buffers/buffer-write-string.js n=1000000 len=1 9.21 % ±12.42% ±17.25% ±24.00%
buffers/buffer-write-string.js n=1000000 len=16 * 5.12 % ±4.58% ±6.53% ±9.52%
buffers/buffer-write-string.js n=1000000 len=32 2.87 % ±8.49% ±12.18% ±17.88%
buffers/buffer-write-string.js n=1000000 len=8 ** 8.27 % ±5.40% ±7.68% ±11.10% |
|
Can you add a printf to fast api function and make sure that it runs? I've had several occasions that I couldn't trigger fast path for super simple calls. |
|
@anonrig You are right. It's never called and I have no idea why. Do you know anyone that might know more? |
|
Ah, it's because buffer is this and not the first arg. Do you know if fast API works with this args? |
|
The first arg (receiver) is the this arg. |
|
Tried with no this and still no success... seems like a dead end for me |
de22cf8 to
63e7cda
Compare
|
This works for me and the fast api path is hit starting around 1e4 iterations in the benchmark: |
|
Got it to work! buffers/buffer-write-string.js n=1000000 str='a' *** 306.67 % ±7.42% ±10.17% ±13.87%
buffers/buffer-write-string.js n=1000000 str='aa' *** 289.45 % ±3.26% ±4.59% ±6.55%
buffers/buffer-write-string.js n=1000000 str='aaaa' *** 271.79 % ±12.09% ±16.96% ±24.00%looks promising |
f3259aa to
d1eb51b
Compare
9c98f8f to
2596951
Compare
2596951 to
6594e2e
Compare
Commit Queue failed- Loading data for nodejs/node/pull/54311 ✔ Done loading data for nodejs/node/pull/54311 ----------------------------------- PR info ------------------------------------ Title buffer: use fast API for writing one-byte strings (#54311) Author Robert Nagy <ronagy@icloud.com> (@ronag) Branch ronag:write-string-fast-api -> nodejs:main Labels buffer, c++, notable-change, author ready, needs-ci Commits 1 - buffer: use fast API for writing one-byte strings Committers 1 - Robert Nagy <ronagy@icloud.com> PR-URL: https://github.com/nodejs/node/pull/54311 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/54311 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - buffer: use fast API for writing one-byte strings ℹ This PR was created on Sat, 10 Aug 2024 19:59:03 GMT ✔ Approvals: 6 ✔ - Michaël Zasso (@targos) (TSC): https://github.com/nodejs/node/pull/54311#pullrequestreview-2231748283 ✔ - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/54311#pullrequestreview-2236268460 ✔ - Santiago Gimeno (@santigimeno): https://github.com/nodejs/node/pull/54311#pullrequestreview-2231856267 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/54311#pullrequestreview-2231867115 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/54311#pullrequestreview-2232130355 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/54311#pullrequestreview-2233878460 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-08-14T11:58:45Z: https://ci.nodejs.org/job/node-test-pull-request/61103/ - Querying data for job/node-test-pull-request/61103/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/10389383045 |
|
Landed in ccf05ef |
|
Access violation occurred in FastWriteString function, causing the process to crash and exit. @ronag
|
This comment was marked as outdated.
This comment was marked as outdated.
|
@ShenHongFei Thanks for reporting! Fix is ready. |
|
I tried applying the patch https://github.com/nodejs/node/pull/54391/files and the problem was solved. Thank you. |
Refs: #54311 (comment) PR-URL: #54391 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
PR-URL: #54310 PR-URL: #54311 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

Uh oh!
There was an error while loading. Please reload this page.