From aa2a441ce639ff821dd7ad07e3a292a2c3d9ba50 Mon Sep 17 00:00:00 2001 From: Keyhan Vakil Date: Sat, 18 Mar 2023 00:09:37 +0000 Subject: [PATCH] src: use SIMD for snapshot checksum Snapshot checksum verification uses `v8::Internal::Checksum`, which uses zlib's adler32 checksum. However it was using the slow version of adler32 for machines with no SIMD. Let's change it to use the SIMD version when it is available. Fortunately the necessary incantations were already included in our _other_ copy of Chromium's zlib in `deps/zlib/zlib.gyp`, so this is mostly just copying from there. On a very recent Intel machine, this speeds up the snapshot checksumming from 870us to 300us (a 570us startup saving), according to: ```bash for i in {1..100}; do ./node --profile-deserialization -e 0 done \ |& grep 'Verifying snapshot checksum' \ | awk '{s+=$5} END{print s/NR}' ``` P.S.: maybe we should just disable this entirely via `--no-verify-snapshot-checksum`? It doesn't feel like a super necessary protection. --- tools/v8_gypfiles/v8.gyp | 133 ++++++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 37 deletions(-) diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 19f224d01b82d8..08bae31cec8a0f 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -4,6 +4,8 @@ { 'variables': { 'V8_ROOT': '../../deps/v8', + 'V8_ZLIB_ROOT': '<(V8_ROOT)/third_party/zlib', + 'arm_fpu%': '', 'v8_code': 1, 'v8_random_seed%': 314159265, 'v8_vector_stores%': 0, @@ -1884,6 +1886,54 @@ }, }, # postmortem-metadata + { + 'target_name': 'v8_zlib_adler32_simd', + 'type': 'static_library', + 'conditions': [ + ['target_arch in "ia32 x64" and OS!="ios"', { + 'defines': [ 'ADLER32_SIMD_SSSE3' ], + 'conditions': [ + ['OS=="win"', { + 'defines': [ 'X86_WINDOWS' ], + },{ + 'defines': [ 'X86_NOT_WINDOWS' ], + }], + ['OS!="win" or llvm_version!="0.0"', { + 'cflags': [ '-mssse3' ], + 'xcode_settings': { + 'OTHER_CFLAGS': [ '-mssse3' ], + }, + }], + ], + }], + ['arm_fpu=="neon"', { + 'defines': [ 'ADLER32_SIMD_NEON' ], + }], + ], + 'include_dirs': [ '<(V8_ZLIB_ROOT)' ], + 'direct_dependent_settings': { + 'conditions': [ + ['target_arch in "ia32 x64" and OS!="ios"', { + 'defines': [ 'ADLER32_SIMD_SSSE3' ], + 'conditions': [ + ['OS=="win"', { + 'defines': [ 'X86_WINDOWS' ], + },{ + 'defines': [ 'X86_NOT_WINDOWS' ], + }], + ], + }], + ['arm_fpu=="neon"', { + 'defines': [ 'ADLER32_SIMD_NEON' ], + }], + ], + 'include_dirs': [ '<(V8_ZLIB_ROOT)' ], + }, + 'sources': [ + '