Skip to content

refactor: generic unbounded cache - #701

Merged
gilescope merged 16 commits into
mainfrom
refactor-generic-synccache
Jul 29, 2026
Merged

refactor: generic unbounded cache#701
gilescope merged 16 commits into
mainfrom
refactor-generic-synccache

Conversation

@janishorsts

@janishorsts janishorsts commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

🛠️ Benefits, Issues Resolved & DX Impact

  • Benefits: Replaced legacy interface{}-based caching with a strongly-typed generic synccache.Cache[K comparable, V any] implementation featuring zero-allocation cache hits (0 B/op), thread-safe single-flight request coalescing (inflight.go), and clean package scoping in internal/synccache.
  • Issues Eliminated: Removed unsafe runtime type assertions and potential nil pointer dereferences across build context resolution callers (buildcontext, cachedmetaresolver, solvecache), and eliminated redundant concurrent load executions for identical in-flight keys.
  • Developer Experience (DX) Impact: Compile-time type safety prevents type assertion bugs; simplified API surface replaces multi-layer context wrapping with direct shared context passing. Comprehensive test coverage added for concurrent loads, context cancellations, and race conditions.

⚡ Performance Impact

Metric Before After Delta
Execution Time 105.4 ns/op 52.8 ns/op -49.9%
Memory Allocations 16 B/op 0 B/op -100.0%
Heap Mallocs 1 allocs/op 0 allocs/op -100.0%

Note: Benchmarks measured on cache hits using Go 1.26 on darwin/arm64.

📦 Binary Size Impact

  • Stripped Size (Before/After/Delta): 31.53 MB / 31.60 MB / +64.5 KB (+0.21%)

@janishorsts janishorsts self-assigned this Jul 21, 2026
@janishorsts
janishorsts requested a review from a team as a code owner July 21, 2026 20:07
@janishorsts
janishorsts requested review from kmannislands and removed request for a team July 21, 2026 20:07
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

➖ Are we earthbuild yet?

No change in "earthly" occurrences

📈 Overall Progress

Branch Total Count
main 4748
This PR 4748
Difference +0

Keep up the great work migrating from Earthly to Earthbuild! 🚀

💡 Tips for finding more occurrences

Run locally to see detailed breakdown:

./.github/scripts/count-earthly.sh

Note that the goal is not to reach 0.
There is anticipated to be at least some occurences of earthly in the source code due to backwards compatibility with config files and language constructs.

Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope

Copy link
Copy Markdown

@janishorsts have a look - it seemed there were a few holes (demonstrated by failing tests). I've patched them with claude's help and also switched from using sleeps to something more event based. (I try and avoid sleeps in tests wherever possible)

Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope

Copy link
Copy Markdown

Feel free to roll back changes you don't like / reimplement!

@janishorsts

Copy link
Copy Markdown
Collaborator Author

@janishorsts have a look - it seemed there were a few holes (demonstrated by failing tests). I've patched them with claude's help and also switched from using sleeps to something more event based. (I try and avoid sleeps in tests wherever possible)

@gilescope, nice. I had no idea golang introduced the "testing/synctest" for concurrency testing last year. I always read release notes.

Can you please have another look? I did a second round of changes, a significant refactoring. Initially, I was not keen on touching the metacontext package. But as it is used only by the cache implementation, I refactored it to be more idiomatic to Golang concepts.

@gilescope gilescope left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a big diff. Just seemed to be one issue around caching timeouts, please review my commit @janishorsts.

@janishorsts janishorsts added the ai-assisted Authored with AI assistance label Jul 28, 2026
@gilescope
gilescope enabled auto-merge (squash) July 29, 2026 07:54
@gilescope
gilescope merged commit 8ead2ca into main Jul 29, 2026
89 checks passed
@gilescope
gilescope deleted the refactor-generic-synccache branch July 29, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Authored with AI assistance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants