Skip to content

Migrate from NAN to N-API#471

Open
James Sigurdarson (jamiees2) wants to merge 4 commits intoconfluentinc:masterfrom
jamiees2:master
Open

Migrate from NAN to N-API#471
James Sigurdarson (jamiees2) wants to merge 4 commits intoconfluentinc:masterfrom
jamiees2:master

Conversation

@jamiees2
Copy link
Copy Markdown

@jamiees2 James Sigurdarson (jamiees2) commented Mar 17, 2026

What

This converts the C++ layer from NAN to N-API. This builds on #281 , but with an up-to-date master, and gets the build and all tests working and passing.

Moving to N-API is pretty important to enable more widespread support for this library, in order to use it with other runtimes, e.g bun/deno. N-API is the current official recommendation by the Node.js project over NAN. N-API also abstracts away v8 internals, leading to fewer node version checks.

This is a fairly large PR since ripping out NAN is a pretty core change to the codebase. I tried my best to keep the changes minimal, but there are some structural changes that were necessary, mainly that some code needed to be converted to templates, and some code had to be moved around to obey the N-API object structure.

Checklist

  • Contains customer facing changes? Including API/behavior changes
    • I am marking this as a No as I did my best to maintain the same contract of the C++ API, and not touch either JS code or librdkafka, which should be the same.
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • I aimed to not change anything besides C++ code in this PR, and expected that the unit+integration test coverage would verify that the signatures would be the same. I am explicitly not adding any features.

References

JIRA:

Test & Review

I ran all tests make test, and make promisified_test. I did not get make e2e passing, since it doesn't seem to be passing on the master branch.

I ran the example performance test to verify that performance is the same:

Producer Rate:  72.13817761594777
Consumer Rate:  79.02436898466523

I ran the same benchmark off of the master branch (NAN version), and got the following numbers:

Producer Rate:  73.25083933976153
Consumer Rate:  77.82450506699665

Note that these benchmarks were just run on my laptop, and not in a CI harness or anything so run-to-run variance is higher. My conclusion is that there is no performance impact.

I intend to start using this version of the library myself in a project I'm working on with real data.

Open questions / Follow-ups

I'll tag Milind L (@milindl) and Charles Lowell (@cowboyd) from #281

This includes revamping a lot of call sites in order to include the NAPI
env, where necessary, and a lot of type modification in order to get the
build working.
} else {
Nan::Utf8String utf8_value(value.As<v8::String>());
string_value = std::string(*utf8_value);
string_value = value.ToString().Utf8Value();
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a bug - I preserved the same behavior from NAN, but this means that an undefined/null value gets passed as the string "undefined" or "null".

I don't want to fix that bug here, but just wanted to call it out since I noticed it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant