Retain label configuration and generation in policy versions - #12
Merged
Merged
Conversation
Parse and retain complete policy-state metadata in authorization and version responses, preserving old-server defaults. Validate generation as an unsigned 64-bit integer and reject Python booleans. Extend model equality and document the per-engine scope of generations.
Contributor
Merging this PR will improve performance by 10.41%
Performance Changes
Tip Curious why performance improved? Comment Comparing |
Keep generation validation in the constructor and avoid repeated optional-field parsing for legacy responses. Cache at most 256 complete immutable versions, keyed by all fields and runtime types, so boolean generations cannot alias valid cached integers. Preserve subclasses by including the requested constructor type in the cache key. Add regressions for cache-key state isolation and benchmarks for complete metadata and changing generations. Same-runtime local comparisons improve version parsing from 4.93 to 3.85 microseconds and 100-item brief batch parsing from 514 to 451 microseconds versus main.
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.
Retain nullable label identifiers and engine generations in
PolicyVersion, authorization responses, and version responses. Older servers default missing fields toNoneand0; frozen model equality includes all state dimensions. Generation is validated as an unsigned 64-bit integer, rejecting booleans and out-of-range values, and is documented as local to an engine instance.The initial migration repeated version validation and construction for each response item, producing six CodSpeed regressions. Reuse immutable policy versions through a bounded 256-entry cache keyed by the model class, every state field, and runtime types; booleans cannot alias cached integers. Avoid repeated helper calls for absent legacy fields. Custom subclasses remain uncached so their constructors and independent state preserve existing behavior. Pass subclass fields by keyword, and retain the two-keyword constructor contract when parsing legacy responses. Cache-isolation tests cover every state dimension, and added benchmarks cover complete modern metadata and continuously changing generations.
Same-runtime local comparisons versus main improve version-response parsing from 4.93 to 3.88 microseconds, one-item brief parsing from 8.24 to 6.97 microseconds, 100-item brief parsing from 514 to 451 microseconds, and 50-item detailed parsing from 336 to 298 microseconds. The final CodSpeed comparison reports 10.41% improvement, one improved benchmark, 30 untouched benchmarks, and no regressions. Refreshing the main baseline also removed the runtime-environment warning.
Exercise the integration suite against REST v0.0.16 and retain v0.0.12 coverage. The current-server test asserts that loaded label configuration is returned with its SHA-256 identifier.
Verification
73 unit tests, all 29 integration cases against both published REST v0.0.12 and v0.0.16, Pyright, Basedpyright with zero warnings, and Markdown lint pass. All 33 benchmark cases pass locally. The subclass constructor regression tests pass; the guard also passes the full unit suite, both type checkers, and same-runtime performance comparisons; the final CodSpeed comparison is green and has no runtime-environment warning. Container tests use isolated Podman storage.