Skip to content

feat(linter): add read_to_arena_str function #11823

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

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jun 19, 2025

Alternative to #11816. Read a file from disk directly into an Allocator.

Unfortunately, involves a pretty egregious hack (see comments in code), but this appears to be the only way that stable Rust provides to read a file into uninitialized memory without UB. Bonkers!

Copy link
Member Author

overlookmotel commented Jun 19, 2025


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.

@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Jun 19, 2025
Copy link

codspeed-hq bot commented Jun 19, 2025

CodSpeed Instrumentation Performance Report

Merging #11823 will improve performances by 15.08%

Comparing 06-19-feat_linter_add_read_to_arena_str_function (dc6f584) with main (f2ce5ad)

Summary

⚡ 1 improvements
✅ 37 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3.5 ms 3.1 ms +15.08%

@overlookmotel overlookmotel marked this pull request as ready for review June 19, 2025 20:41
@overlookmotel overlookmotel requested a review from camc314 as a code owner June 19, 2025 20:41
@overlookmotel
Copy link
Member Author

@camc314 I think this should work, but we'll need to check it doesn't regress performance before making a release that uses it.

There are issues in Rust repo about optimizations that make fs::read do less syscalls, and I'm not 100% sure whether this method will also get the benefit of those optimizations or not (or whether it makes any practical difference either way).

@camc314 camc314 changed the base branch from 06-19-feat_allocator_add_allocator_alloc_slice_copy_method to graphite-base/11823 June 19, 2025 22:01
@camc314 camc314 changed the base branch from graphite-base/11823 to 06-19-feat_allocator_add_allocator_alloc_slice_copy_method June 19, 2025 22:07
@graphite-app graphite-app bot changed the base branch from 06-19-feat_allocator_add_allocator_alloc_slice_copy_method to graphite-base/11823 June 20, 2025 00:37
@overlookmotel overlookmotel force-pushed the 06-19-feat_linter_add_read_to_arena_str_function branch from c1576bc to 9261bd0 Compare June 20, 2025 00:50
@overlookmotel overlookmotel changed the base branch from graphite-base/11823 to 06-19-feat_allocator_add_allocator_alloc_slice_copy_method June 20, 2025 00:50
@graphite-app graphite-app bot changed the base branch from 06-19-feat_allocator_add_allocator_alloc_slice_copy_method to graphite-base/11823 June 20, 2025 00:51
@graphite-app graphite-app bot force-pushed the graphite-base/11823 branch from 3487e9a to f2ce5ad Compare June 20, 2025 00:57
@graphite-app graphite-app bot force-pushed the 06-19-feat_linter_add_read_to_arena_str_function branch from 9261bd0 to 17cb9ca Compare June 20, 2025 00:57
@graphite-app graphite-app bot changed the base branch from graphite-base/11823 to main June 20, 2025 00:58
@graphite-app graphite-app bot force-pushed the 06-19-feat_linter_add_read_to_arena_str_function branch from 17cb9ca to 4adbe4b Compare June 20, 2025 00:58
@camc314
Copy link
Contributor

camc314 commented Jun 20, 2025

$ hyperfine --warmup 3 -n "main" '../../Boshen/oxc/target/release/oxlint --silent' -n "read str into allocator" '../../Boshen/oxc/target/release/str-into-alloc --silent'  -i
Benchmark 1: main
  Time (mean ± σ):     319.6 ms ±   2.3 ms    [User: 3132.9 ms, System: 185.8 ms]
  Range (min … max):   315.6 ms … 322.7 ms    10 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: read str into allocator
  Time (mean ± σ):     318.7 ms ±   3.3 ms    [User: 3126.3 ms, System: 181.0 ms]
  Range (min … max):   315.4 ms … 326.6 ms    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  read str into allocator ran
    1.00 ± 0.01 times faster than main
$ hyperfine --warmup 3 -n "main" '../../Boshen/oxc/target/release/oxlint --silent' -n "read str into allocator" '../../Boshen/oxc/target/release/str-into-alloc --silent'  -i
Benchmark 1: main
  Time (mean ± σ):     322.2 ms ±   5.6 ms    [User: 3128.5 ms, System: 185.6 ms]
  Range (min … max):   316.0 ms … 332.7 ms    10 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: read str into allocator
  Time (mean ± σ):     323.3 ms ±   8.8 ms    [User: 3126.2 ms, System: 180.1 ms]
  Range (min … max):   315.3 ms … 336.4 ms    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  main ran
    1.00 ± 0.03 times faster than read str into allocator

perf appears to be identical (or within noise limits)

( i benched this on my PR that's on top of this one so we're actually using this fn!)

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jun 20, 2025
Copy link
Contributor

camc314 commented Jun 20, 2025

Merge activity

Alternative to #11816. Read a file from disk directly into an `Allocator`.

Unfortunately, involves a pretty egregious hack (see comments in code), but this appears to be the only way that stable Rust provides to read a file into uninitialized memory without UB. Bonkers!
@graphite-app graphite-app bot force-pushed the 06-19-feat_linter_add_read_to_arena_str_function branch from 4adbe4b to dc6f584 Compare June 20, 2025 09:04
@graphite-app graphite-app bot merged commit dc6f584 into main Jun 20, 2025
23 checks passed
@graphite-app graphite-app bot deleted the 06-19-feat_linter_add_read_to_arena_str_function branch June 20, 2025 09:07
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants