Skip to content

Conversation

@mscdex
Copy link
Contributor

@mscdex mscdex commented Aug 15, 2021

This is an alternative to #39701 that adds a base64 SIMD library. The gains with this solution are significantly greater than those in #39701.

To answer a question/concern from the other PR: I did compare with a build with -march=native and it performed identical to the generic binary when it came to the base64 encoding benchmark, so at least gcc doesn't seem to automagically optimize like we can when explicitly using SIMD (when available).

The way this base64 library works is it uses CPU feature detection at runtime on x86 and for ARM it's only enabled when --dest-cpu is either arm64 (where NEON is always available) or arm with --with-arm-fpu set to neon. In all other cases a generic implementation similar to (but probably better than) the one in #39701 gets used as a fallback.

For now, I'm only enabling it for normal base64 encoding. The end goal is to use the library for base64url encoding too and hopefully for base64 decoding as well. Supporting those other functions will take some work because base64url is not currently supported by the library and the library's decoding does not natively support V8's 16-bit strings and IIRC the decoder's behavior does not match that of node's decoder (e.g. ignoring whitespace or other characters).

Anyhow, here is the benchmark result on a Core i7-3770K:

                                                   confidence improvement accuracy (*)   (**)  (***)
buffers/buffer-base64-encode.js n=32 len=67108864        ***    165.37 %       ±0.22% ±0.30% ±0.40%

and unlike in #39701, this time I had the chance to run the benchmark on an armv8 board (Odroid C2):

                                                  confidence improvement accuracy (*)   (**)  (***)
buffers/buffer-base64-encode.js n=32 len=67108864        ***     66.13 %       ±0.47% ±0.62% ±0.81%

@mscdex mscdex added the performance Issues and PRs related to the performance of Node.js. label Aug 15, 2021
@nodejs-github-bot nodejs-github-bot added meta Issues and PRs related to the general management of the project. needs-ci PRs that need a full CI run. labels Aug 15, 2021
@mscdex mscdex removed the needs-ci PRs that need a full CI run. label Aug 15, 2021
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@mscdex mscdex added buffer Issues and PRs related to the buffer subsystem. and removed meta Issues and PRs related to the general management of the project. labels Aug 16, 2021
@jasnell
Copy link
Member

jasnell commented Aug 20, 2021

Generally looks good but can I ask you to include a README.md or guide that describes where the dep comes from, how to update it, the latest commit sha, etc? Either that, or a makefile in deps/base64 that allows me to make update to pull the latest down.

@mscdex
Copy link
Contributor Author

mscdex commented Jul 9, 2022

@jasnell I've added a README.md. Let me know if it looks good enough.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@mscdex mscdex force-pushed the base64-perf-simd branch from cfdee83 to 2aaf1f6 Compare July 9, 2022 23:22
@nodejs-github-bot

This comment was marked as outdated.

@mscdex mscdex force-pushed the base64-perf-simd branch 3 times, most recently from eed8c55 to 3d89745 Compare July 10, 2022 01:52
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@mscdex
Copy link
Contributor Author

mscdex commented Jul 10, 2022

Alright, I tried with CI, but it seems to be failing on unrelated flaky tests and unreliable Jenkins connections (at least more consistently on armv7l).

@nodejs-github-bot
Copy link
Collaborator

@mscdex mscdex force-pushed the base64-perf-simd branch from 3d89745 to f561f31 Compare July 14, 2022 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buffer Issues and PRs related to the buffer subsystem. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants