Lazy type-as-constructor get! defaults (closes #202) - #215
Draft
rodrigomha wants to merge 1 commit into
Draft
Conversation
…oses #202) The 3-arg get!(dict, key, default) evaluates `default` eagerly on every call, allocating a throwaway collection even on the common hit path. Per odow's suggestion in #202, a type is itself a zero-arg constructor, so get!(Set{...}, dict, key) / get!(Dict{...}, dict, key) / get!(Vector{String}, dict, key) build the default lazily (only on a miss) with no anonymous closure - simpler than get!(() -> ..., ...). Sites (all insert-then-mutate, so a fresh instance per miss is required - the type-constructor form provides exactly that): - network_models/network_reductions.jl: reduction tracker + constraint map wiring - ac_transmission_models/branch_constructor.jl: inter-area branch typed-dict assembly - operation/template_validation.jl: bus regulators, outage types, per-type validation
|
Performance Results
|
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.
Closes #202.
The 3-arg
get!(dict, key, default)evaluatesdefaulteagerly on every call, allocating athrowaway collection even on the common hit path (the key already present). Per odow's suggestion
in #202, a type is itself a zero-arg constructor, so
get!(Set{…}, dict, key)builds the defaultlazily - only on a miss - with no anonymous closure. Simpler than both the eager form and the
get!(() -> …, dict, key)closure form.Sites converted
All are insert-then-mutate (a following
push!/_add_to_branch_map!), so a fresh instance permiss is required - the type-constructor form provides exactly that (never a shared const).
network_models/network_reductions.jl- reduction tracker wiring + constraint map/submap (the hottest, per-arc/per-type)ac_transmission_models/branch_constructor.jl- inter-area branch typed-dict assembly (per branch)operation/template_validation.jl- bus regulators, outage types, per-type validation (per element)Pure mechanical swaps (11 lines, 11±). Compile-verified locally; leaving as draft for CI to run
the full suite (local cross-package dev env currently can't resolve
main's pins - unrelated to this change).🤖 Generated with Claude Code
https://claude.ai/code/session_01W1bssU5YnY8eZWQD9apDBM