Replace arrow_field with a memoizing arrow_field_ref - #34
Draft
emilk wants to merge 4 commits into
Draft
Conversation
`arrow_field_ref` returns a `FieldRef`, built once and thereafter just an `Arc::clone`, for descriptors that carry a cache. The cache is a `&'static OnceLock<FieldRef>` rather than an inline cell: descriptors are `const`, so a cell stored by value would be a fresh, always-empty one at every use site — a cache that silently never hits. `with_field_cache` takes the reference, so all uses of a `const` share the one `static`. Descriptors built without it still work, rebuilding the field per call. `arrow_field` is gone; `*desc.arrow_field_ref()` clones an owned `Field` if you need one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Covers the case a by-value cell would get wrong: a separate copy of the `const` still shares the one cached `FieldRef`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`with_field_cache` becomes `#[doc(hidden)] __with_field_cache`. Nothing about the mechanism changes — the cache still has to point at a `static`, because a `const` is inlined at every use site and an interior-mutable field would be a fresh, always-empty cell on each call (exactly what `clippy::declare_interior_mutable_const` warns about). But it is no longer something a caller is expected to reach for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Aug 27, 2026
Open
Merged
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.
Related
What
ColumnDesc::arrow_field_ref() -> FieldRef, built once and thereafter just anArc::clone.arrow_fieldis removed, as suggested —*desc.arrow_field_ref()clones an ownedFieldif you need one. It was only used in tests.The cache is a
&'static OnceLock<FieldRef>, not an inlineOnceLockfield. That is the part worth reviewing: the derive emits descriptors aspub const, so a cell stored by value would be materialized fresh at every use site and would never hit — a cache that silently does nothing. Holding a reference to astaticmeans all uses of aconstshare one cell, andColumnDescstaysCopy.The derive attaches one per column:
with_field_cacheis public, so hand-written descriptors can do the same. Without it the field is rebuilt per call — correct, just not free. The cache does not take part inPartialEqorDebug.OnceLockrather thanLazyLock:LazyLock's initializer is part of its type and cannot capture, so it could not see the descriptor'snameandmetadata.get_or_initlets the descriptor supply the builder, so one method serves derived and hand-written descriptors alike.Testing
New test covers repeat calls sharing an allocation, a separate copy of the
constsharing it too (the case a by-value cell gets wrong), an uncached descriptor rebuilding each time, and the cache not affecting equality. Full CI job run locally on 1.95.0.Compatibility
Breaking:
arrow_fieldis gone, andColumnDescgains a private field.🤖 Generated with Claude Code