Repository navigation
Conversation
Work in progress, saved before review. Rewrites the wrapper on N-API, builds the Linux prebuilds in the Lambda nodejs:22 image for x64 and arm64, and adds equivalence, leak, undefined-behaviour and wrong-input tests against the 4.0.1 NAN binding.
…d arrays - Report the index memory (heap nodes or mapped file) to V8 with napi_adjust_external_memory, so dropped indexes are collected: 1000 loads of a 4 MB index keep ~20 alive instead of ~360 (4.0.1). - Compile with -ffp-contract=off: arm64 fused a*b+c into FMA and gave different distances and trees than x86-64; results are now bit-identical across architectures. - Accept numeric typed arrays as vectors in addItem and getNNsByVector, read straight from their backing store (4.0.1 ignored them). - Tests: external-memory-test.js, typed-array-test.js; README updated.
The binding only loads node-gyp-build. level (and through it the native leveldown) is only used by the tools/ scripts that build test data, and bindings by nothing: every consumer installed and shipped a second native module it never loaded. tools/ is no longer published.
The package only serves bot-api, which follows the AWS Lambda Node.js runtime: target the latest stable Node-API instead of keeping Node 16 compatibility. engines: node >= 22.14.0. - NAPI_VERSION 10: node-addon-api reports napi_cannot_run_js when an exception is thrown while the environment shuts down. - The result keys (neighbors, distances) are created with node_api_create_property_key_utf8: -3% per query on a small index, no measurable change on a real one (3631, 1024 dimensions). Prebuilds rebuilt in the Lambda nodejs:22 image. Same results as 4.0.1 (60/60) on x64 (Node 22, 24) and arm64, every suite passing.
index.d.ts declares the Annoy class (export =) with its metric, vector (arrays and numeric typed arrays) and result types; getNNsByVector and getNNsByItem are overloaded on includeDistances. tests/types.ts must compile under --strict (without skipLibCheck, so the declarations are checked too) and its misuses must not; it runs in make test.
Benjaminrivard
approved these changes
Nov 12, 2026
maximepichou
approved these changes
Nov 12, 2026
Taken from the prebuild workflow artifact (run 43196701137, built on the macOS runners from 5b8020e), so macOS installs no longer compile the addon. The linux prebuilds of the same run are byte-identical to the committed ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Main goal: stop this addon from blocking Node.js upgrades. 4.0.1 is a NAN addon: its binary only works for one Node ABI, so on any other Node version
npm installrecompiles it on the installing machine, against that machine's glibc. Built on a recent workstation, it then fails to load on an older glibc such as the AWS Lambda one (GLIBC_2.38 not found), and every Node upgrade means rebuilding it.5.0.0 is a Node-API 10 addon with prebuilds: one binary per platform that loads on every Node >= 22.14 (24, 26...), built in the AWS Lambda
nodejs:22image and needing at most glibc 2.17. No compatibility with Node < 22.14 is kept: the goal is to keep working on newer runtimes.Secondary gains: linux-arm64, bit-identical results on x64 and arm64, index memory reported to V8, typed-array vectors, TypeScript declarations, no more
leveldowninstalled with the package.What
NAPI_VERSION10) replacing the NAN wrapper;engines.node >= 22.14.0.linux-x64andlinux-arm64built in the Lambdanodejs:22image (Dockerfile),darwin-arm64anddarwin-x64on macOS runners (.github/workflows/prebuild.yml).scripts/check-prebuild-symbols.shfails if a Linux binary needs more than glibc 2.34.-ffp-contract=off(arm64 fuseda*b+cinto FMA, which changed distances and trees).napi_adjust_external_memory, so dropped indexes are collected: 1000 loads of a 4 MB index keep ~20 alive instead of ~360.addItemandgetNNsByVectorread numeric typed arrays straight from their backing store (4.0.1 ignored them).level(and the nativeleveldown) andbindingsmove to devDependencies;tools/is no longer published.index.d.ts), checked under--strictbytests/types.ts.Validation
.annoyfiles byte-identicalnodejs:24image (x64, arm64), Node 26.12.0Downstream validation (production replays, arm64 deployment) is in the internal pull requests that consume the canary
5.0.0-canary.2.Not in this PR
v5.0.0and publish from a checkout ofmaster(npm publish). The prebuild workflow only builds and tests: it does not publish and uses no secrets. All four prebuilds are committed (the darwin ones come from the workflow artifact; its linux ones are byte-identical to the committed ones). The canary5.0.0-canary.2lacks the darwin prebuilds.