-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Improve MonoDict and TripleDict data structures #13387
Comments
First shot at improvements of MonoDict and TripleDict data structures |
comment:1
Attachment: trac_13387.patch.gz Initial tests show only a doctest failure due to a doctest change introduced on #12313 on |
comment:3
Excellent work! Looks promising. I tested
but already for the
I don't think I'll even understand modern CPU's ... (that or Anyway, at least the iteration needs some work (nice that cython generators now work!)
but as you see, that's easily fixed. You just have to extract the actual keys. Doing it this way might report errors a bit better than with the unsafe casting of
Pitfall, by the way:
So:
Note that my key, So we should document that one should not use |
comment:4
I noticed this python-ideas thread. So there seems some interest for dictionaries keyed by ID elsewhere too (although they're not mentioning a weak key dict) |
comment:5
I see a logistic problem: The aim of #13904 is to fix some problems introduced with #715. It should be a quick solution, since otherwise #715 will be unmerged. However, the ticket here also depends on #12313, which has a positive review, but isn't merged yet. So, that's too slow. Therefore, I suggest that #13904 shall use the ideas from here, but only applied to I think it is worth while to provide the In other words: I suggest to split this ticket (one part done in #13904 ASAP, the other part later in #12313), so that this ticket shall be marked as a duplicate. Do you agree? |
comment:6
Replying to @simon-king-jena:
There is nothing wrong with EDIT: It used to say except for an eraser problem we don't know how to fix. We should solve that for now by forbidding the problematic keys in the documentation. In other words: "Don't use Memory management, deallocation, and weakref callbacks are genuinely hard ... |
Attachment: trac_13387-rebased.patch.gz rebased to apply cleanly over #12313 (28 jan 2013) |
comment:8
Concerning the timing reported on #12313:300, with the patch here we get
which is an improvement of 91 ns over the 331 ns reported there. Since a normal dictionary times 110 ns for this operation, and this patch avoids the internal use of another dictionary lookup in We now have
That is a bit of a gain over Concerning Jeroen's original report, we now have (#12313 + #13387)
versus reference timing
To compare, on this machine, the same test with just #12313 takes
so the improvements here do significantly reduce the regression originally reported by Jeroen. |
comment:9
Incidentally, doing a The only scenario that would lead to undue deletions due to callback would be if a callback on a key with For the truly paranoid, we could check in the |
comment:10
Somewhere I had posted a general |
comment:11
It's where everything is: #12313 (idkey_dict attachment) |
Attachment: trac_13387-fast-weakref-calls.patch.gz Use PyWeakref_GetObject |
comment:12
Yippee!! using
So we shave a little more off (something like 30ns, i.e., some 15% on a simple MonoDict lookup) Apply trac_13387-rebased.patch trac_13387-fast-weakref-calls.patch TODO: Further improvement: in the coercion framework, hardwire the use of MonoDict, provide get and set cdef methods and call those to eliminate further method lookup overhead. |
comment:13
I think the patches on this ticket have value already, so I'm refiling under "sage-feature". We'd already benefit from merging these tickets as-is. That said, there is probably room for some easy further improvements, so we can wait with merging it unless someone deems this tickets needs to be a dependency for another one that needs merging. |
comment:14
and
I have noticed that these timings can vary quite a bit between compiles and branch names. I guess loops this tight get sensitive to cache alignment and fortunate code locations. Apply trac_13387-rebased.patch trac_13387-fast-weakref-calls.patch trac_13387-cdef_monodict_access.patch |
Attachment: trac_13387-cdef_monodict_access.patch.gz cdef get and set access to MonoDict to speed up coercion lookups |
comment:15
Hm. Seems |
comment:16
Replying to @nbruin:
I think this is why I originally dropped get/set for What about having different names for the getters and setters (mget/mset versus tget/tset)? It would avoid the duplication, but would certainly not be very clean. |
comment:17
By the way, what patches are to be applied? The following? Apply trac_13387-rebased.patch trac_13387-fast-weakref-calls.patch trac_13387-cdef_monodict_access.patch |
comment:18
Replying to @simon-king-jena:
I think it's worse than the current situation. The reality is that The patch order is correct, as with the Apply statement before. Note that the patchbot results page sorts records by the time local to the bot, so reports are not necessarily in reverse chronological order. It did get a "tests past" with the current patch sequence. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Combined patch of previous work, rel 5.8.beta0 |
comment:43
Attachment: trac_13387-combined-rel5.8.b0.patch.gz If patchbot starts with sage-5.8.beta0, it should first apply one patch from #12313 (namely the one that reverts the usage of a callback for the weak reference to homsets), and then Apply trac_13387-combined-rel5.8.b0.patch trac_13387-guard_GC.patch |
This comment has been minimized.
This comment has been minimized.
comment:44
I am puzzled. The patchbot is applying the correct patches in the correct order to the correct sage version, but almost all patches fail to apply. For the record, I have
on top of sage-5.8.beta0. |
comment:45
To be on the safe side, I was deleting the three patches and downloaded them from trac. They applied fine. So, I think the error is on the side of the patchbot. |
comment:46
Argh. The patch keeps failing to apply! Could it be that the "official" version of 5.8.beta0 is different from the one that I had downloaded? |
Changed work issues from rebase to none |
This comment has been minimized.
This comment has been minimized.
comment:47
I don't see why you think rebasing is necessary. The previous patchbot logs already show that the ticket here applies cleanly on 5.8beta0 and that tests pass. The fact that #12313 fails to apply with its currently stated dependencies is expected: The patchbot doesn't understand "merge with". However, if patches apply here and tests pass, that's an implicit validation of #12313 (with the understanding that this ticket needs to be merged after it). I'm also refiling this as a "defect" rather than an enhancement: Some of the fixes here fix real bugs (although we might not have seen them triggered). Let's try again, since the "guard_GC" patch didn't get picked up by the bot before: Apply trac_13387-combined.patch trac_13387-guard_GC.patch |
Attachment: trac_13387-guard_gc.patch.gz Guard against GC during dict resize |
This comment has been minimized.
This comment has been minimized.
comment:48
IIRC, patchbot won't apply patches that have an uppercase letter in the name. Hence, I renamed your second patch. Apply trac_13387-combined.patch trac_13387-guard_gc.patch |
comment:49
What is the startup_modules script complaining about? |
comment:50
Replying to @simon-king-jena:
It's complaining that there seems to be a new module now, If someone has a recommended way of accessing this functionality without importing gc, that's fine with me. Moving the |
Reviewer: Simon King |
comment:51
With sage-5.8.beta0 plus #14159 plus #12313 plus #13387, make ptest works fine for me. The ideas behind the patches from here are well-documented in comments in the code. The precautions taken to prevent trouble with garbage collection happening in the wrong moment seem reasonable to me. And we have seen that the performance is fine as well. Hence, it is a positive review. |
comment:52
PS: From my perspective, it is no problem that gc is imported during Sage startup. |
Merged: sage-5.8.beta2 |
comment:54
Please see #14254 for a blocker follow-up. |
On #715 and #12313 some variants of WeakKeyRef data structures are introduced, used in caching for, among other things, uniqueness of parents and coercions. In #12313 comment 162 is some data on how these data structures can be improved.
Apply:
Depends on #11521
Depends on #12313
CC: @simon-king-jena @jpflori
Component: memleak
Author: Nils Bruin
Reviewer: Simon King
Merged: sage-5.8.beta2
Issue created by migration from https://trac.sagemath.org/ticket/13387
The text was updated successfully, but these errors were encountered: