-
Notifications
You must be signed in to change notification settings - Fork 790
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
PoC: Compiler caches #18190
base: main
Are you sure you want to change the base?
PoC: Compiler caches #18190
Conversation
❗ Release notes requiredCaution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository:
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request. You can open this PR in browser to add release notes: open in github.dev
|
I have added a CWT-based cache as well (optional, off by default), but it really needs more testing to make sure nothing is leaking. |
while not cts.Token.IsCancellationRequested do | ||
if this.GetEvictCount() > 0 then | ||
this.TryEvictItems () | ||
// do! Task.Delay(100, cts.Token) |
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.
Exponential backoff based on number of evicted items?
Did I evict 0 - can afford a longer delay.
A lot of stuff evicted - try again shortly after.
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.
Yes, that was my idea as well
if options.Weak then | ||
let weak = Weak<'Key>(key) | ||
this.ConditionalWeakTable.TryAdd(key :> obj, weak) |> ignore | ||
weak.Collected.Add(this.RemoveCollected) |
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 will not be collected, because there is another reference to key
from the inner storage of this.Store
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.
I can see them getting collected if I trigger the GC. I.e. I see finalizer getting called on them.
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.
Ah, disregard, I thought I've pushed updated version which wraps key in a weak reference. Will push it on Monday.
This is a very first naive draft of universal cache for compiler internals.
Currently it's very
dumbstraightforward - have an underlying concurrent dictionary, evict on every insert.Things it lacks:
It currently solves the only issue versus using
ConcurrentDictionarry
- eviction. It can evict things, though not in the most efficient way possible.Personally, I think, that first it has to be at least as good as
ConcurrentDictionary
+eviction, so we can enable some caching for tooling as well as for compiler.