perf: leak names in BtreeError InvalidRootPage/MasterEntryNotFound (#679) - #680
Merged
Merged
Conversation
Replaces the owned `String` in these two cold sqlite_master corruption/lookup variants with a leaked `&'static str`, removing their drop glue. This is intentional: both variants are only constructed on rare error paths (corrupt rootpage, missing schema entry during delete), so leaking the handful of bytes is a deliberate trade against the drop cost these variants otherwise impose on every Result<_, BtreeError> in TableCursor::seek's hot per-page binary search. std::mem::needs_drop::<BtreeError>() still returns true overall because BtreeError::Pager(PagerError) transitively owns a `path: String` (PagerError::HotJournal/Wal) -- fixing that is a separate, out-of-scope change (see PR description). Refs: follow-up to #677, closes #679
iheitlager
force-pushed
the
fix/679-btree-error-shrink-needs-drop
branch
from
August 31, 2026 09:48
13576f3 to
1c958e8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #677/#679:
BtreeError::InvalidRootPage/MasterEntryNotFoundowned a
String, makingBtreeErrornon-trivially-droppable and forcing anout-of-line
drop_in_place::<BtreeError>on everyResult<_, BtreeError>produced inside
TableCursor::seek's hot per-page binary search, paidlog2(N)times per row.Both variants only fire on rare
sqlite_mastercorruption/lookup paths(bad rootpage, missing entry on delete), so the fix leaks the name
(
Box::leak(name.to_string().into_boxed_str())→&'static str) instead ofowning a
String. A few dozen leaked bytes on an error path that typicallypropagates straight to the caller is a fine trade for removing drop glue
from the hot-path type.
Bench results (
make -C tests/performance crud, filtered toread_join,bench_1mb.db, 16700 rows)Criterion reported a -20.8% mean-time improvement for
read_join(p < 0.05).Note on the
needs_dropacceptance criterionstd::mem::needs_drop::<BtreeError>()is stilltrueafter thischange — not
falseas the ticket's acceptance criteria literally ask for.Root cause:
BtreeError::Pager(PagerError)transitively owns apath: StringviaPagerError::HotJournal/PagerError::Wal, so the wholeenum keeps drop glue regardless of what's done to
InvalidRootPage/MasterEntryNotFound. Boxing/leakingStringfields specifically inBtreeError's own two variants was the only thing in scope for thisticket; fully eliminating
needs_dropwould require the same treatment onPagerError(touchespager.rsin ~4 places +pager/checkpoint.rs),which is a materially larger, separate change.
Per the ticket's own guidance ("if a measurable gap remains ... note it
rather than chasing it further"), I'm not expanding scope here. The bench
result above shows this fix alone recovers a solid majority of the
regression even though
needs_dropstaystrue— LLVM's actual codegendecision (drop shim size/complexity, not just the boolean) is what mattered
in practice. Happy to file a follow-up ticket for the
PagerErrorside ifthe remaining ~59ns/row-to-oracle gap on
read_joinis worth chasing.Test plan
cargo test— full suite passescargo clippy --all-targets -- -D warnings— cleancargo fmt --check— cleanbtree::error/btree::masterunit tests updated for the new fieldtypes and pass
Spend: matched estimate (small, mechanical).
Closes #679