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
GC optimization: don't track simple tuples and dicts #48938
Comments
Split out from bpo-4074, here is a standalone patch which disables GC The patch also adds a function named is_tracked() to the gc module. |
This additional patch also optimizes simple dicts, it must be applied Together these two patches make it so that e.g. a dict of tuples or |
I've looked very quickly over your patches to try to figure what rule For tuples, I think the rule is: Is that right? If so, you could perform the same optimization on the Why do empty tuples have to be tracked? The dict patch adds a boolean flag to the dict data structure to What's the rule for when a dict can be tracked or untracked? Do you |
Le mercredi 17 décembre 2008 à 23:56 +0000, Daniel Stutzbach a écrit :
Roughly, yes. Exactly, it is "if it points only to untrackable objects".
Yes, but I prefer to concentrate on those two core types now, which are
Actually, they are never tracked, which means calling
Yes, probably. I thought a dedicated flag may be faster but I will try
Only if it is not tracked. Once a dict is tracked, it cannot become |
So, I've tried without the dedicated flag in the dict object and it's as |
IIUC, you try to find various places where tuples are created, and check I think this approach is difficult to maintain, and also may miss some I'd rather see that integrated into collection: e.g. when iterating over |
Unfortunately, the check is O(n), so it can get a little expensive. I Can _PyObject_GC_UNTRACK() be safely called from tp_traverse? |
Not in the typical case, I guess. *If* you have to go through all
Correct. Collection is O(n) per object, anyway.
No. However, I doubt that iterating over the object twice is |
Le jeudi 18 décembre 2008 à 06:12 +0000, Martin v. Löwis a écrit :
But what counts is where tuples can be created in massive numbers or
That's what I had tried at first, but it crashes. I haven't Also, this approach is more expensive since it involves checking tuples |
To be clearer, I tried adding it to the tp_traverse method of tuples. I |
Here is an alternate patch which does the tuple optimization in the GC. |
Here is a patch which combines the alternate approach (untrack simple Some eyes are welcome. |
Still, I think this patch does too much code duplication. There should
I'm skeptical. It could well be *less* expensive, namely if many tuples |
Hello again,
The point was to avoid slowing down the critical path of tuple creation By the way, perhaps pybench should grow a GC test (e.g. derived from |
Here is a new patch against trunk. |
Here is a benchmark ripped from the Computer Language Shootout Running pybench --with-gc doesn't show any performance variation, which |
The patch looks fine to me. Some documentation is missing, still: I'm not sure whether you actually want to integrate SHOW_TRACK_COUNT |
I've added tracking statistics for tuples, documentation for |
Thanks for the review, by the way! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: