Skip to content

Use adaptive sparse encoding for metadata tables - #164484

Open
TaKO8Ki wants to merge 2 commits into
rust-lang:mainfrom
TaKO8Ki:sparse-metadata-tables
Open

TaKO8Ki wants to merge 2 commits into
rust-lang:mainfrom
TaKO8Ki:sparse-metadata-tables

Conversation

@TaKO8Ki

@TaKO8Ki TaKO8Ki commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

r? @nnethercote

I have added this implementation partially following the approach suggested in the existing FIXME comment.

Each 64-element block stores a cumulative count of preceding non-default values, enabling constant-time lookup by combining that count with a popcount of the bitmap bits before the requested position.

In local measurements, .rmeta file sizes decreased for all four crates in both Check and Release builds:

Crate Check reduction Release reduction
tokio 33.68% 27.25%
tokio-util 29.18% 21.93%
serde_core 34.45% 18.37%
serde_json 27.07% 16.96%

LLM disclosure: I used an LLM for some of the analysis in this PR.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 17, 2026
@TaKO8Ki

TaKO8Ki commented Oct 17, 2026

Copy link
Copy Markdown
Member 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 Oct 17, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 17, 2026
Use adaptive sparse encoding for metadata tables
@rust-bors

rust-bors Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: cef35eb (cef35eba824ffd8f61ba555d23a22c5938662a2a)
Base parent: 2834d57 (2834d57549e77dbd7e9fa42f51aa349f8a00368b)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (cef35eb): comparison URL.

Overall result: ❌ regressions - please read:

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.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@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.4% [0.1%, 2.6%] 97
Regressions ❌
(secondary)
1.0% [0.1%, 2.6%] 87
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.1%, 2.6%] 97

Max RSS (memory usage)

Results (primary -3.8%, secondary -4.2%)

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)
- - 0
Improvements ✅
(primary)
-3.8% [-7.2%, -0.7%] 230
Improvements ✅
(secondary)
-4.2% [-7.1%, -1.0%] 225
All ❌✅ (primary) -3.8% [-7.2%, -0.7%] 230

Cycles

Results (primary 1.8%, secondary -6.4%)

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

mean range count
Regressions ❌
(primary)
1.8% [1.8%, 1.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.4% [-9.1%, -2.8%] 6
All ❌✅ (primary) 1.8% [1.8%, 1.8%] 1

Binary size

Results (primary -0.6%)

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)
- - 0
Improvements ✅
(primary)
-0.6% [-0.6%, -0.5%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-0.6%, -0.5%] 4

Bootstrap: 489.187s -> 489.99s (0.16%)
Artifact size: 406.93 MiB -> 409.04 MiB (0.52%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 17, 2026
@TaKO8Ki

TaKO8Ki commented Oct 18, 2026 •

Copy link
Copy Markdown
Member Author

I think the instruction-count regressions, averaging 0.66% across the affected benchmark cases, are an acceptable trade-off for the 20.15% average reduction in crate metadata size. https://perf.rust-lang.org/compare.html?start=2834d57549e77dbd7e9fa42f51aa349f8a00368b&end=cef35eba824ffd8f61ba555d23a22c5938662a2a&stat=size%3Acrate_metadata

@Kobzol

Kobzol commented Oct 18, 2026

Copy link
Copy Markdown
Member

CC @jyn514 those metadata size reduction results will probably be interesting :)

@TaKO8Ki
TaKO8Ki marked this pull request as ready for review October 18, 2026 09:39
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 18, 2026
@TaKO8Ki TaKO8Ki added the perf-regression-triaged The performance regression has been triaged. label Oct 20, 2026

@nnethercote nnethercote left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs some detailed comments explaining how the new scheme works.

The metadata wins are very nice. It might be possible to reduce the instruction count regressions.

View changes since this review

len
};
let sparse =
u32::try_from(non_defaults).is_ok() && index_bytes + non_defaults * width < len * width;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The sparse form is used if it saves any amount of space. If a table is almost full the space saving will be small but we will pay the full speed cost of the sparse layout. It would be worth trying a few different policies, e.g. only use the sparse form if the table is less than 90% full or 75%, or 50%. The best fraction will hopefully give most of the metadata size reductions while incurring a smaller instruction count cost.

return Default::default();
}
let base =
u32::from_le_bytes(metadata.blob()[start + 8..start + 12].try_into().unwrap());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could read metadata.blob()[start + 12] and then read from offsets 0 and 8, which would avoid one bounds check.

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 22, 2026
@TaKO8Ki
TaKO8Ki force-pushed the sparse-metadata-tables branch from fa18cf1 to 0a7e283 Compare October 22, 2026 20:02
@rustbot

rustbot commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 22, 2026
Use adaptive sparse encoding for metadata tables
@TaKO8Ki
TaKO8Ki force-pushed the sparse-metadata-tables branch from 0a7e283 to de21c98 Compare October 22, 2026 20:07
@rust-bors

rust-bors Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

Hint: if you want to run another try build, you do not need to manually cancel the previous one. Just run @bors try and bors will cancel the previous build automatically.

@TaKO8Ki

TaKO8Ki commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

This pull request is already queued and waiting for a try build to finish.

@rust-lang rust-lang deleted a comment from rust-bors Bot Oct 22, 2026
@rust-bors

rust-bors Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Trying commit de21c98 with merge a7d52aa…

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/39846373166

rust-bors Bot pushed a commit that referenced this pull request Oct 22, 2026
Use adaptive sparse encoding for metadata tables
@rust-lang rust-lang deleted a comment from rust-timer Oct 22, 2026
@TaKO8Ki

TaKO8Ki commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

This pull request is already queued and waiting for a try build to finish.

@rust-bors

rust-bors Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Trying commit de21c98 with merge 6ea9563…

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/39902737994

rust-bors Bot pushed a commit that referenced this pull request Oct 23, 2026
Use adaptive sparse encoding for metadata tables
@TaKO8Ki

TaKO8Ki commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@rust-timer build a7d52aa

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued a7d52aa with parent c303e41, future comparison URL.
There are currently 0 preceding artifacts in the queue.
It will probably take at least ~0.8 hours until the benchmark run finishes.

This branch has not been deployed

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

Labels

perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-perf Status: Waiting on a perf run to be completed. T-compiler Relevant to the compiler 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