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

feat(data_structures): zero-cost NonMaxU32 type #9883

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Mar 19, 2025

Introduce our own NonMaxU32 type.

This version has an advantage over nonmax's version on Linux, Mac and WASI. On those platforms, it utilizes the std::os::fd::BorrowedFd type, which is a true non-max type. Therefore, conversion to/from u32 is completely zero cost, whereas previous version stores the number as a NonZeroU32 and has to perform n ^ u32::MAX on every read/write.

NonMaxU32 has a niche, so Option<NonMaxU32> is 4 bytes.

On platforms which don't have std::os::fd::BorrowedFd (Windows), we fallback to an implementation which uses NonZeroU32 internally, same as before.

Copy link
Contributor Author

overlookmotel commented Mar 19, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

codspeed-hq bot commented Mar 19, 2025

CodSpeed Performance Report

Merging #9883 will not alter performance

Comparing 03-19-feat_data_structures_zero-cost_nonmaxu32_type (4d4a502) with main (2e023ab)

Summary

✅ 33 untouched benchmarks

Base automatically changed from 03-19-ci_miri_run_miri_on_oxc_data_structures_crate_with_all_features_enabled to main March 19, 2025 04:53
@overlookmotel overlookmotel changed the base branch from main to graphite-base/9883 March 19, 2025 05:39
@overlookmotel overlookmotel force-pushed the 03-19-feat_data_structures_zero-cost_nonmaxu32_type branch from 99c72e2 to faf48ce Compare March 19, 2025 05:39
@overlookmotel overlookmotel changed the base branch from graphite-base/9883 to 03-19-feat_data_structures_add_assert_unchecked_macro March 19, 2025 05:39
@overlookmotel overlookmotel force-pushed the 03-19-feat_data_structures_add_assert_unchecked_macro branch from 2ded941 to e1cd1a7 Compare March 19, 2025 05:44
@overlookmotel overlookmotel force-pushed the 03-19-feat_data_structures_zero-cost_nonmaxu32_type branch from faf48ce to 513f5ec Compare March 19, 2025 05:44
@overlookmotel overlookmotel changed the base branch from 03-19-feat_data_structures_add_assert_unchecked_macro to graphite-base/9883 March 19, 2025 08:04
@overlookmotel overlookmotel force-pushed the 03-19-feat_data_structures_zero-cost_nonmaxu32_type branch from 513f5ec to 9694667 Compare March 19, 2025 08:04
@overlookmotel overlookmotel changed the base branch from graphite-base/9883 to 03-19-fix_linter_react_exhaustive-deps_report_longest_dependency March 19, 2025 08:04
@graphite-app graphite-app bot force-pushed the 03-19-fix_linter_react_exhaustive-deps_report_longest_dependency branch 2 times, most recently from cb0e6b7 to 61aba28 Compare March 19, 2025 09:04
@graphite-app graphite-app bot force-pushed the 03-19-feat_data_structures_zero-cost_nonmaxu32_type branch from 9694667 to a111895 Compare March 19, 2025 09:04
@graphite-app graphite-app bot changed the base branch from 03-19-fix_linter_react_exhaustive-deps_report_longest_dependency to graphite-base/9883 March 20, 2025 01:03
@graphite-app graphite-app bot force-pushed the 03-19-feat_data_structures_zero-cost_nonmaxu32_type branch from a111895 to 40ea7e0 Compare March 20, 2025 01:08
@graphite-app graphite-app bot force-pushed the graphite-base/9883 branch from 61aba28 to 2e023ab Compare March 20, 2025 01:08
@graphite-app graphite-app bot changed the base branch from graphite-base/9883 to main March 20, 2025 01:09
@graphite-app graphite-app bot force-pushed the 03-19-feat_data_structures_zero-cost_nonmaxu32_type branch from 40ea7e0 to 4d4a502 Compare March 20, 2025 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant