-
Notifications
You must be signed in to change notification settings - Fork 0
β‘ Bolt: Replace expensive setdefault with explicit check in HullKVCache #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## 2024-05-18 - Unintended file modifications from tests | ||
| **Learning:** Running `uv run pytest` or targeted tests and scripts locally can regenerate files in the `results/` directory, causing unintended modifications to tracked benchmark baselines and snapshots. | ||
| **Action:** Always check `git status` after running tests/benchmarks and run `git restore --staged results/` and `git checkout results/` to clean up the repository before committing and submitting PRs. | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |||||||||||||||
| HardmaxResult, | ||||||||||||||||
| NumberLike, | ||||||||||||||||
| ValueLike, | ||||||||||||||||
| _as_fraction, | ||||||||||||||||
| _coerce_key, | ||||||||||||||||
| _coerce_value, | ||||||||||||||||
| _normalize_number, | ||||||||||||||||
|
|
@@ -205,10 +204,12 @@ def _rebuild_if_needed(self) -> None: | |||||||||||||||
| total_value_sum = [Fraction(0) for _ in range(self._value_width or 0)] | ||||||||||||||||
|
|
||||||||||||||||
| for index, (key, value) in enumerate(self._entries): | ||||||||||||||||
| bucket = aggregates.setdefault( | ||||||||||||||||
| key, | ||||||||||||||||
| {"value_sum": [Fraction(0) for _ in value], "count": 0, "entry_indices": []}, | ||||||||||||||||
| ) | ||||||||||||||||
| # β‘ Bolt Optimization: Avoid expensive eager evaluation of setdefault arguments | ||||||||||||||||
| # Creating [Fraction(0) for _ in value] on every iteration is costly | ||||||||||||||||
|
Comment on lines
+207
to
+208
|
||||||||||||||||
| # β‘ Bolt Optimization: Avoid expensive eager evaluation of setdefault arguments | |
| # Creating [Fraction(0) for _ in value] on every iteration is costly | |
| # Avoid allocating the default value_sum list for keys already present. |
Copilot
AI
Apr 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new hot-loop pattern does two dict lookups for existing keys (if key not in aggregates then aggregates[key]). Since this change is specifically for performance, consider using a single-lookup pattern (e.g., bucket = aggregates.get(key) / try: ... except KeyError:) to avoid the extra lookup when keys repeat heavily.
| if key not in aggregates: | |
| aggregates[key] = {"value_sum": [Fraction(0) for _ in value], "count": 0, "entry_indices": []} | |
| bucket = aggregates[key] | |
| bucket = aggregates.get(key) | |
| if bucket is None: | |
| bucket = {"value_sum": [Fraction(0) for _ in value], "count": 0, "entry_indices": []} | |
| aggregates[key] = bucket |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from bytecode import BoundedMemoryVMCase, lower_program, r43_bounded_memory_vm_cases | ||
| from bytecode import lower_program, r43_bounded_memory_vm_cases | ||
| from exec_trace import Program, TraceInterpreter | ||
|
Comment on lines
+5
to
6
|
||
|
|
||
| from .exact_hardmax import extract_stack_slot_operations | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new .jules note seems process-/tooling-related and not directly tied to the HullKVCache performance change described in the PR. If itβs intended to be checked in, please update the PR description to include it; otherwise consider dropping it from this PR to avoid unrelated diffs.