Skip to content

Avoid repeated numeric-list scans during trajectory serialization - #990

Draft
bradhilton wants to merge 1 commit into
mainfrom
hayek/memoize-numeric-pickle-lists-20260927
Draft

bradhilton wants to merge 1 commit into
mainfrom
hayek/memoize-numeric-pickle-lists-20260927

Conversation

@bradhilton

Copy link
Copy Markdown
Collaborator

Trajectory string interning checked whether a list contained only numeric values before consulting its graph memo, then returned without recording the list. Shared token/logprob-like vectors were therefore scanned repeatedly through each alias. Consult the existing per-traversal memo first and record numeric lists without copying or changing their values.

Validation:

  • 30 compact-serialization tests pass, including a regression that reduces 64 scans to one, mutation between traversals, aliases, cycles, signed zero/NaN, and pickle/cloudpickle round trips.
  • Actual cloudpickle.dumps of public synthetic trajectory-group callbacks produces byte-identical baseline/candidate payloads across five alternating repetitions. The alias-heavy case falls from 0.4518 s to 0.0080 s median CPU time (56.48×); independent equal vectors show no regression (0.4798 s to 0.4679 s). These are synthetic results; live alias frequency and end-to-end preparation gains are unmeasured.
  • Ruff check/format and git diff --check pass. Independent source review passed.

The memo remains local to one traversal. No new API, global cache, tokenization behavior, or active-run source adoption.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant