Skip to content

Commit feb58df

Browse files
committed
zlib: run zlib CPU feature detection at binding init
zlib detects CPU features only on crc32(0, NULL, 0) or when a stream is initialized. zlib.crc32() calls crc32() with a buffer, so it used the portable code until some deflate or inflate stream had been created. Prime the detection when the binding is initialized so zlib.crc32() uses the SIMD path from the start.
1 parent 6bc4d25 commit feb58df

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎src/node_zlib.cc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,11 @@ void Initialize(Local<Object> target,
21842184
Local<Value> unused,
21852185
Local<Context> context,
21862186
void* priv) {
2187+
// zlib only runs its CPU feature detection on crc32(0, NULL, 0) or when a
2188+
// stream is initialized. Do it here so zlib.crc32() gets the SIMD path even
2189+
// when no compression stream has been created yet.
2190+
crc32(0, nullptr, 0);
2191+
21872192
Environment* env = Environment::GetCurrent(context);
21882193

21892194
MakeClass<ZlibStream>::Make(env, target, "Zlib");

0 commit comments

Comments
 (0)