Skip to content

Comments

feat(napi): add node_api_create_object_with_properties support for enum creation#2990

Merged
Brooooooklyn merged 7 commits intomainfrom
copilot/fix-34149896-131389850-6e6b5c74-c4e5-4900-b576-f875918ca1ea
Nov 27, 2025
Merged

feat(napi): add node_api_create_object_with_properties support for enum creation#2990
Brooooooklyn merged 7 commits intomainfrom
copilot/fix-34149896-131389850-6e6b5c74-c4e5-4900-b576-f875918ca1ea

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Node.js 22 introduced node_api_create_object_with_properties which creates objects with properties in a single FFI call instead of N+1 calls (one to create, N to set properties). This reduces overhead when creating enum objects.

Changes

FFI Binding (crates/sys/src/functions.rs)

  • Added node_api_create_object_with_properties declaration under napi10 feature

Runtime Helper (crates/napi/src/bindgen_runtime/mod.rs)

  • Added create_object_with_properties helper that uses optimized API when:
    • napi10 + node_version_detect + dyn-symbols features enabled
    • Runtime detects Node.js ≥ 22
  • Falls back to napi_create_object + napi_set_named_property otherwise
  • Requires dyn-symbols to avoid linking against unavailable symbols on older Node.js versions

Code Generation (crates/backend/src/codegen/enum.rs)

  • Pre-computes enum variant values before creating property descriptors
  • Passes descriptors to helper function for object creation
  • Works transparently with both optimized and fallback paths

Example

For an enum with 3 variants:

Before: 4 FFI calls

napi_create_object() + 
napi_set_named_property() * 3

After (Node.js 22+): 1 FFI call

node_api_create_object_with_properties()

Addresses: nodejs/node#45905

Original prompt

This section details on the original issue you should resolve

<issue_title>[feat] [perf] recently merged node_api_create_object_with_properties</issue_title>
<issue_description>nodejs/node#45905

node_api_create_object_with_properties seems have better performance.

Would be nice to see napi-rs faster binding.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@graphite-app
Copy link

graphite-app bot commented Nov 3, 2025

How to use the Graphite Merge Queue

Add the label ready-to-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copilot AI changed the title [WIP] [feat] [perf] recently merged node_api_create_object_with_properties feat: Add node_api_create_object_with_properties support for enum creation Nov 3, 2025
Copilot AI requested a review from Brooooooklyn November 3, 2025 09:53
@Brooooooklyn Brooooooklyn force-pushed the copilot/fix-34149896-131389850-6e6b5c74-c4e5-4900-b576-f875918ca1ea branch from bacc5f8 to 11abd6a Compare November 27, 2025 09:44
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Comment @coderabbitai help to get the list of available commands and usage tips.

@Brooooooklyn Brooooooklyn force-pushed the copilot/fix-34149896-131389850-6e6b5c74-c4e5-4900-b576-f875918ca1ea branch from 11abd6a to 4e7ffc1 Compare November 27, 2025 10:42
@Brooooooklyn Brooooooklyn marked this pull request as ready for review November 27, 2025 10:45
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn Brooooooklyn changed the title feat: Add node_api_create_object_with_properties support for enum creation feat: add node_api_create_object_with_properties support for enum creation Nov 27, 2025
@Brooooooklyn Brooooooklyn changed the title feat: add node_api_create_object_with_properties support for enum creation feat(napi): add node_api_create_object_with_properties support for enum creation Nov 27, 2025
@Brooooooklyn Brooooooklyn merged commit e4f5360 into main Nov 27, 2025
74 checks passed
@Brooooooklyn Brooooooklyn deleted the copilot/fix-34149896-131389850-6e6b5c74-c4e5-4900-b576-f875918ca1ea branch November 27, 2025 15:21
@github-actions github-actions bot mentioned this pull request Nov 27, 2025
graphite-app bot pushed a commit to oxc-project/oxc that referenced this pull request Dec 2, 2025
…16403)

NAPI-RS 3.6.0 makes a change to the ordering of objects. It now puts optional fields last.

This made tests in `napi/parser` for module record fail when we tried to update (#16383) because the `module_request` field of `ExportEntry` moves to last which breaks the snapshots.

The change in NAPI-RS is unlikely to be reverted, because it's a sizeable perf optimization: napi-rs/napi-rs#2990

To work around this problem:

1. Move the field in the `ExportEntry` intermediate struct in `napi/parser` to last, so NAPI's output matches what you'd expect from the struct definition.
2. Alter the `#[estree]` attr on `ExportEntry` struct in `oxc_syntax` crate to match.

Note: The `ExportEntry` struct in `napi/parser` is just an intermediate structure used for serialization. So I think it's fine to fiddle with its field order. The actual `ExportEntry` struct used in the module record is in `oxc_syntax` crate, and it remains unaltered.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…xc-project#16403)

NAPI-RS 3.6.0 makes a change to the ordering of objects. It now puts optional fields last.

This made tests in `napi/parser` for module record fail when we tried to update (oxc-project#16383) because the `module_request` field of `ExportEntry` moves to last which breaks the snapshots.

The change in NAPI-RS is unlikely to be reverted, because it's a sizeable perf optimization: napi-rs/napi-rs#2990

To work around this problem:

1. Move the field in the `ExportEntry` intermediate struct in `napi/parser` to last, so NAPI's output matches what you'd expect from the struct definition.
2. Alter the `#[estree]` attr on `ExportEntry` struct in `oxc_syntax` crate to match.

Note: The `ExportEntry` struct in `napi/parser` is just an intermediate structure used for serialization. So I think it's fine to fiddle with its field order. The actual `ExportEntry` struct used in the module record is in `oxc_syntax` crate, and it remains unaltered.
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.

[feat] [perf] recently merged node_api_create_object_with_properties

2 participants