Skip to content

Eliminate allocations in no-op write operations (Set.With, Map.With) - #94

Merged
marcelocantos merged 1 commit into
masterfrom
eliminate-noop-write-allocations
Mar 8, 2026
Merged

Eliminate allocations in no-op write operations (Set.With, Map.With)#94
marcelocantos merged 1 commit into
masterfrom
eliminate-noop-write-allocations

Conversation

@marcelocantos

Copy link
Copy Markdown
Collaborator

Add same field to CombineArgs for identity detection in leaf nodes.
When a write doesn't change the collection, leaves return themselves
unchanged, short-circuiting all spine allocation. Tree.WithWith uses
cached CombineArgs to avoid per-call boxing of equality/hash functions.
Bonus: mutating inserts also improved (Map.Insert 1k: 12→3 allocs).

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Add `same` field to CombineArgs for identity detection in leaf nodes.
When a write doesn't change the collection, leaves return themselves
unchanged, short-circuiting all spine allocation. Tree.WithWith uses
cached CombineArgs to avoid per-call boxing of equality/hash functions.
Bonus: mutating inserts also improved (Map.Insert 1k: 12→3 allocs).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@marcelocantos
marcelocantos merged commit 5cf2c80 into master Mar 8, 2026
4 checks passed
@marcelocantos
marcelocantos deleted the eliminate-noop-write-allocations branch March 8, 2026 23:19
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