← Back to Pull requests

Give hot dumped types one-letter serde names #922

Closed
unknown closed this pull request without merging on Sep 24, 2026 09:50 UTC
View on GitHub
unknown unknown commented on Sep 24, 2026 07:33 UTC
Author

Should also be improved by https://github.com/twittner/minicbor/pull/73

Session dumps are CBOR maps keyed by field and variant name, so key strings are most of a dump.
Measured on two sessions, key strings were 76% of a 500-snippet, 250-function REPL session and 69% of a session holding 2,000 small dicts.
The worst offenders are types written once per value, heap entry or location: every Value wrote its variant name (InternString is 13 bytes around a 1–3 byte id), every heap entry refcount/color/data, every dict item key/value/hash.

This renames every field and variant of those types to one upper-case letter (first letter of the name, else the next unused letter in it, else the first unused letter of the alphabet):
Value, HeapEntry, CcColor, List, Tuple, Dict (its hand-written impl), DictEntry, SetEntry, CodeRange, LocationEntry and CodeLoc.
Everything else keeps readable names; per-function and one-off types are a small share of a dump.

Notes for review:

  • HeapEntry and CcColor are in heap/mod.rs; the change there is serde attributes only.

  • CodeLoc is public in monty-types, so its serde shape for hosts becomes {"L": …, "C": …}.

  • HeapData variants are not renamed: heap_payloads! forwards variant attributes to HeapReadOutput, which has no serde derive.

  • Dumps are unpublished in this format, so there are no aliases; dump_v13.bin is regenerated (18.7 KB → 12.3 KB).

  • CLAUDE.md records the convention: a new field or variant on these types takes an unused letter.

  • #909 adds SuspendPosition to code.rs; it should get the same treatment once both land.
  • Measured with these renames applied on top of #909:

    | | before | after |
    |---|---|---|
    | 2,000-dict session dump | 817 KB | 407 KB |
    | 500-snippet session dump | 322 KB | 211 KB |
    | session_load (local criterion) | 588 µs | 541 µs (−8.6%) |
    | session_dump (local criterion) | 145.6 µs | 149.0 µs (noise) |

    On CodSpeed most of session_dump's cost was glibc realloc copying the growing buffer, which the local macOS run does not show, so CodSpeed is the better measure of dump time.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01DFJ9rUjXVHCtQpxhZvoiGb

    <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Shrinks session dumps by renaming serde fields and variants on frequently written types to single upper-case letters. Key strings were ~70% of dump size; this halves it (817 KB → 407 KB for a 2,000-dict session, 322 KB → 211 KB for a 500-snippet session) while load time drops roughly 8% and dump time is unchanged.

    Notes

  • Renames fields on per-value, per-heap-entry, per-function, and per-frame types: Value, HeapEntry, CcColor, List, Tuple, Dict, DictEntry, SetEntry, CodeRange, LocationEntry, CodeLoc, Function, Signature, Identifier, NameScope, Code, ExceptionEntry, SerializedFrame, Instance, Closure, FunctionDefaults, and the hot HeapData variants; all other types keep readable names.

  • CodeLoc is public in monty-types, so its host-facing serde shape becomes {"L": …, "C": …}.

  • Dumps are unpublished in this format, so no aliases are needed; dump_v13.bin is regenerated.

  • HeapReadOutput no longer repeats the registry's serde attributes, since they cannot apply to it; the registry's "append-only" notes are dropped since CBOR tags variants by name, not position.

  • dump_rejects_transient_gc_colors was updated to forge the now one-letter C/B keys instead of the old text keys.

  • The datatest harness now round-trips every non-suspending case's idle heap through the dump codec and re-dumps the result, which must match byte for byte, except xfail cases whose expected failure must come from the run itself; mount-fs suspensions also round-trip so open files pass through the dump format.

  • The dump fixture was expanded to cover previously undumped heap types (iterators, dict views, dates, bytes, ranges, slices, bound methods, random.Random) and now suspends inside an exec() frame with a globals dict, finally, except, and __init__; regenerating it asserts the suspension landed on host_call. slice.indices() is documented as unimplemented.

  • CLAUDE.md documents the convention: new fields or variants on these types take an unused letter.
  • <sup>Written for commit 4a5294f7bf0e83d048aafc76da73aecc1565e3fd. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/922?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 631 lines (+473 / -158) across 7 files Reviewer: rewitt94 Review duration: 136m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 631 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.386
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #922"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%
    Repository