Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert NodeId from an alias for usize to u32-sized opaque type #381

Merged
merged 1 commit into from
Oct 13, 2024

Conversation

robertknight
Copy link
Owner

Align the representation of NodeId values with the FlatBuffers schema, which uses uint (u32) as the type, except for operator inputs and outputs where ints are used, with negative values representing missing optional inputs.

Since node IDs are in the range [0, i32::MAX] we can reserve higher values as a niche, making Option<NodeId> the same size as a NodeId.

Performance-wise the main function of interest is Graph::run_plan. Testing with GPT-2 which has 3.3K operations, the change appears to be a small win or neutral. The time spent in run_plan drops from ~3.2% of runtime to ~3.0%.

Align the representation of NodeId values with the FlatBuffers schema, which
uses `uint` (u32) as the type, except for operator inputs and outputs where
`int`s are used, with negative values representing missing optional inputs.

Since node IDs are in the range `[0, i32::MAX]` we can reserve higher values as
a niche, making `Option<NodeId>` the same size as a `NodeId`.
@robertknight robertknight merged commit d7a3490 into main Oct 13, 2024
2 checks passed
@robertknight robertknight deleted the u32-node-id branch October 13, 2024 17:52
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