-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: x/exp/maps: Shrink #54454
Comments
Currently the |
Definitely agree that directly fixing the underlying issues would be better, but it's also true that the issues have been opened for years, and there seem to be no consensus on how to proceed (or even whether we can proceed). This proposal should be seen as an effective intermediate step, as it offers a clean way forward even if at a later date we actually fix #20135 and/or #19094.
I think the simplest way is to implement it in |
Shrink-on-delete seems straightforward, we just need someone to implement it. Josh already checked in most of the mechanism needed for the tooManyOverflowBuckets change. "can" = yes, "how" = allocate a person to it. |
My interpretation of Josh's comment was the opposite, i.e. that the mechanisms needed for the tooManyOverflowBuckets were somewhat unlikely to help with #20135. As an additional hurdle, And, while I haven't given this too much thought, I can imagine some tricky tradeoffs when dealing with how to deal with the case of a map that starts growing in the middle of a shrink operation. On the topic of capacity, and intersecting with the previous point, what should the map do with a map with a high Lastly, how do we plan to ensure that the fix for #20135 won't hurt workloads some people may care about, especially since there may be no available workaround for them? All of this for the simpler case of shrink-on-delete1; the case of grow-on-read is even fuzzier and may not be solved for quite a while (especially considering the potential performance implications). Mind you, I am not saying these are insurmountable issues, or that this proposal is an actual alternative to solving them properly. I am just arguing that it has been 5+ years, and that maybe we shouldn't let perfect be the enemy of good (especially in case good won't hurt us in the future, as we would have an easy way to guarantee compatibility across versions). Footnotes
|
I'm just advocating that we've long avoided adding API for situations where we could fix the issue without adding API. I understand that could lead to long delays in getting things implemented, but that's the tradeoff we have historically made. Top of mind recently, see #29951.
It is a good question. I remember when reviewing that change that it seemed applicable to me. Maybe Josh was seeing something I didn't.
That is a good point. We probably don't want to shrink if people do the map clear idiom + reinsert a new set of stuff. Perhaps we only start shrinking after 2N operations, so that N delete + N add involves no shrinking. There's definitely a tradeoff here between responsiveness when you use fewer entries and extra work that needs to be done to regrow.
I suspect we could deal with this the way inserts work. When we grow from capacity N to 2N, we do enough work at each insert that the grow work is guaranteed to be done by the time the number of entries reaches 2N.
I think this is a case of tuning a heuristic. We do at some point need to give up on the hint and start shrinking. (I guess the other option is to always respect the hint, but I think that overassumes accurate hints.)
It's going to hurt someone, I'm not too hung up on that. Performance optimization is seldom a win-win. I'm looking for something as good or better than an 80% win / 20% lose. |
It sounds like we believe this need can be addressed with better tuning, rather than adding new API. That would suggest we should decline this proposal. Do I have that right? |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
I propose to add, to partially address #20135 and #19094 (and the many external issues linked in those discussions), a
Shrink
function tox/exp/maps
1 with the following semantics:As an initial implementation,
Shrink
would likely just check if any of the following conditions is true, in which case it would perform the appropriate action:In the future, this may be potentially extended to consider memory pressure, or alternatively turned into a no-op if the runtime were to fully address both #20135 and #19094 (although even with those implemented,
Shrink
could still be used to handle the case of a map that receives no reads and writes).Users today can either use
Clone
or perform a manual clone operation of an existing map, but they have no visibility over the internal state of the map, so they can not know whether doing so will actually decrease memory usage, or if they are just wasting CPU cycles. Users could approximate this by manually keeping track of the high watermark and comparing it to the current length of the map, but this 1) can be quite difficult to do, as all map writes need to be instrumented and 2) it still does not address the "map is growing" case.With the proposed addition, users could instead periodically simply call
Shrink
when the map is not in use to ensure that memory is not leaked. Note that this proposal also addresses the case in which a map stops receiving writes (or reads+writes) completely (that would not be covered by any existing or proposed built-in runtime mechanism, as they all require at least some operation to piggyback on).Footnotes
While this would be exposed in
x/exp/maps
, it will likely require the bulk of the implementation to be inruntime
. ↩The text was updated successfully, but these errors were encountered: