Skip to content

[EXPERIMENT] Use AtomicSharedVector for token streams#159048

Draft
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:AtomicSharedVector
Draft

[EXPERIMENT] Use AtomicSharedVector for token streams#159048
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:AtomicSharedVector

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

No description provided.

It currently doesn't include the length. It should. This change makes it
more like other `StableHash` impls for vec-like types.
@rustbot rustbot added A-tidy Area: The tidy tool S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Jul 10, 2026
@rust-log-analyzer

This comment has been minimized.

This adds a dependency on a new crate: `shared_vector`.

It's done for efficiency: `AtomicSharedVector<T>` stores everything
(strong refcount, len, capacity, and elements) in a single allocation,
as opposed to `Arc<Vec<T>>` which requires two allocations.

This also requires changing the `Vec<TokenTree>` argument of
`TokenStream::new` to `shared_vector::Vector<TokenTree>`.

Some of the changes are because the API is slightly different. There are
also various `FIXME(shared_vector)` comments for places where
`shared_vector` has suboptimal behaviour that might be improved in the
future.
@nnethercote

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
[EXPERIMENT] Use `AtomicSharedVector` for token streams
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 68032ac (68032ac7ef7217bc2f45415e2ad8fd9660e9b7f0)
Base parent: d465559 (d465559281ebfb5b586913285f4d40f9b518b729)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (68032ac): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
-0.5% [-1.1%, -0.2%] 126
Improvements ✅
(secondary)
-0.7% [-2.4%, -0.0%] 94
All ❌✅ (primary) -0.5% [-1.1%, -0.2%] 126

Max RSS (memory usage)

Results (primary -1.3%, secondary 1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.5% [0.6%, 3.2%] 6
Regressions ❌
(secondary)
5.8% [0.6%, 10.3%] 18
Improvements ✅
(primary)
-1.9% [-4.4%, -0.7%] 29
Improvements ✅
(secondary)
-3.1% [-5.8%, -0.7%] 19
All ❌✅ (primary) -1.3% [-4.4%, 3.2%] 35

Cycles

Results (secondary 3.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.4% [1.9%, 8.6%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 490.768s -> 491.381s (0.12%)
Artifact size: 389.74 MiB -> 389.73 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 10, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

icount results look great but the cycle results don't. deep-vector is the most affected benchmark, and it has the best icount results and the worst cycle results.

@Kobzol

Kobzol commented Jul 10, 2026

Copy link
Copy Markdown
Member

Let's see if it wasn't noise.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
[EXPERIMENT] Use `AtomicSharedVector` for token streams
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d19c964 (d19c9643c9a237dbe1644b4916bc58194c49e24e)
Base parent: cb014fc (cb014fcb149e44d8aa16a8f66c9f2b1762f034f8)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (d19c964): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-1.2%, -0.2%] 125
Improvements ✅
(secondary)
-0.7% [-2.4%, -0.1%] 87
All ❌✅ (primary) -0.5% [-1.2%, -0.2%] 125

Max RSS (memory usage)

Results (primary -1.5%, secondary 3.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.9% [0.5%, 1.6%] 4
Regressions ❌
(secondary)
4.9% [0.8%, 15.3%] 26
Improvements ✅
(primary)
-1.8% [-3.4%, -0.6%] 28
Improvements ✅
(secondary)
-3.5% [-4.9%, -2.7%] 5
All ❌✅ (primary) -1.5% [-3.4%, 1.6%] 32

Cycles

Results (primary 2.2%, secondary 3.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.2% [2.1%, 2.3%] 2
Regressions ❌
(secondary)
4.5% [1.4%, 8.2%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.6%, -2.3%] 2
All ❌✅ (primary) 2.2% [2.1%, 2.3%] 2

Binary size

Results (primary 0.0%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.0%] 7
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 20
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 7

Bootstrap: 490.017s -> 491.992s (0.40%)
Artifact size: 389.92 MiB -> 389.99 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 10, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

Much the same as the first run.

deep-vector is the most affected benchmark, and it has the best icount results and the worst cycle results.

This makes sense, because it's very parser/token heavy.

@rust-bors

rust-bors Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #159293) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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

Labels

A-tidy Area: The tidy tool S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants