Skip to content

Replace github.com/hashicorp/golang-lru with a custom lru cache - #4196

Merged
derekparker merged 5 commits into
go-delve:masterfrom
qmuntal:lrucache
Nov 25, 2025
Merged

derekparker merged 5 commits into
go-delve:masterfrom
qmuntal:lrucache

Conversation

@qmuntal

@qmuntal qmuntal commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

(Feel free to disregard this PR is you don't like what's in in)

Delve uses a LRU cache to speed up some workflows. It just makes a basic use of it: adding and getting entries. Implementing that subset using the Go standard library is straightforward, it can be done in 70 lines of code. IMO dropping an external dependency is worth the small maintenance overhead of implementing a custom basic LRU cache.

@aarzilli aarzilli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall this looks correct to me.

Comment thread pkg/proc/lrucache.go Resolved
@aarzilli

aarzilli commented Nov 6, 2025

Copy link
Copy Markdown
Member

If we decide to switch from hashicorp/lru to this (I have no opinion in merit, I leave it to Derek) I think we should have some tests.

@qmuntal

qmuntal commented Nov 6, 2025

Copy link
Copy Markdown
Contributor Author

If we decide to switch from hashicorp/lru to this (I have no opinion in merit, I leave it to Derek) I think we should have some tests.

Added some basic tests

@derekparker derekparker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks great, thanks!

You can fix the capslock CI failures by running go run _scripts/gen-capslock-all.go locally (need to update the test output... and very frustrating that they seemed to have changed their output format for capability names). Also, I feel that this new code still deserves its own package, so can you move your LRU implementation & tests into pkg/proc/internal/lru (or similar).

@derekparker

Copy link
Copy Markdown
Member

@qmuntal hey just wanted to ping if you have time to address the above. Thanks!

@qmuntal

qmuntal commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

go run _scripts/gen-capslock-all.go

Wops, forgot about this PR. Addressing your comments right now.

@derekparker derekparker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@derekparker
derekparker merged commit 867c71b into go-delve:master Nov 25, 2025
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.

3 participants