-
-
Notifications
You must be signed in to change notification settings - Fork 552
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
Clean up in coerce_dict #24135
Comments
This comment has been minimized.
This comment has been minimized.
Commit: |
New commits:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:10
cc chapoton because this is also relevant for Python 3. |
comment:11
Can you also justify 8 a little too? I was only able to get a loose understanding from a quick search. Maybe I am too traditional, but why remove the explicit return values? diff --git a/src/sage/structure/coerce_dict.pyx b/src/sage/structure/coerce_dict.pyx
index bbd1ca7..cc2d04f 100644
--- a/src/sage/structure/coerce_dict.pyx
+++ b/src/sage/structure/coerce_dict.pyx
@@ -821,16 +869,15 @@ cdef class MonoDict:
#on cyclic GC)
cdef int MonoDict_traverse(MonoDict op, visitproc visit, void *arg):
- if op.table == NULL:
+ if op.table is NULL:
return 0
Py_VISIT3(<PyObject*>op.eraser, visit, arg)
cdef size_t i
for i in range(op.mask + 1):
cursor = &op.table[i]
- if cursor.key_id != NULL and cursor.key_id != dummy:
+ if valid(cursor.key_id):
Py_VISIT3(cursor.key_weakref, visit, arg)
Py_VISIT3(cursor.value, visit, arg)
- return 0
@@ -859,16 +906,17 @@ cdef int MonoDict_clear(MonoDict op):
del tmp
for i in range(mask+1):
cursor = &(table[i])
- if cursor.key_id != NULL and cursor.key_id != dummy:
+ if valid(cursor.key_id):
cursor.key_id = dummy
Py_XDECREF(cursor.key_weakref)
Py_XDECREF(cursor.value)
- PyMem_Free(table)
- return 0
+ sig_free(table)
+
(<PyTypeObject*>MonoDict).tp_traverse = <traverseproc>(&MonoDict_traverse)
(<PyTypeObject*>MonoDict).tp_clear = <inquiry>(&MonoDict_clear)
+
cdef class TripleDictEraser:
"""
Erases items from a :class:`TripleDict` when a weak reference becomes I am assuming 5 is for better consistency with Python3. Although I think that Trivial and I know you essentially simply moved it, but only 2 spaces instead of 4:
Also with its new placement, it does not need an |
comment:12
Replying to @tscrim:
Conceptually, these functions do not return anything. It is really analogous to a plain Python function which always returns |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:17
Replying to @tscrim:
The new class |
comment:18
Replying to @tscrim:
Obviously. If we are implementing a kind of dict, we should use
Done. |
This comment has been minimized.
This comment has been minimized.
comment:19
I ended up doing a lot more cleanup in this version. Please review. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:21
Thank you for the explanations. All of the changes make sense to me. However, multiple patchbots are reporting multiple random seg faults. So something seems to be subtly breaking. |
comment:22
Replying to @tscrim:
I know, that was because I made a mistake in By the way, I realize that I'm making quite a lot of changes in this ticket. What started as a plan to fix the If there are certain changes that you cannot accept (either because you disagree or you don't understand), I can try to revert those. |
This comment has been minimized.
This comment has been minimized.
comment:23
Replying to @jdemeyer:
Ah, I see. I couldn't quite tell if the patchbot reports were current or not.
It's good to get things done.
I think I understand all of the changes and agree with them (or at least do not have any reason to disagree). So if the latest patchbots come back clean, then it will be a positive review. |
comment:24
Replying to @tscrim:
I believe that the patchbot icon which is displayed on the Trac page (i.e. this page) only considers the up-to-date reports. As I'm writing this comment, I see a status of "pending", meaning that no patchbot has tested this latest version. |
comment:25
Replying to @jdemeyer:
I've seen it as pending before when one of them is still working but another has finished and came back green. Although that might have been on a much older version of the patchbot. |
comment:26
Greenbot. |
Reviewer: Travis Scrimshaw |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:
|
comment:31
Added some harmless comments. |
Changed branch from u/jdemeyer/clean_up_in_coerce_dict to |
Deprecate various arguments which should have been deprecated in Empty lists while creating parents #15367.
Use a tuple instead of a list to throw away. This is very slightly faster.
Use safe memory functions from cysignals instead of
PyMem
functions.Split
__init__
into__cinit__
and__init__
.Rename the
iteritems()
method toitems()
.Introduce a new inline function
valid(ptr)
to replace the very commonptr != NULL and ptr != dummy
.Change type of
key_id
fromvoid*
toPyObject*
. This avoids a lot of casts.Use a custom class with
@cython.freelist
instead of aPyCapsule
to wrap aPyObject*
.In
tp_clear
, only delete references to elements contained in the dict. Move deallocation of the data structure to__dealloc__
.Use random 31-bit multipliers (instead of
13
and503
) in the hash function forTripleDict
. This might give better mixing for large sizes (in any case, it can't hurt).Rename
dummy
->deleted_key
to make it more clear what it means. Also, there was no reason that this was of typebytes
. Now it is simply created byobject()
.Change the logic of the
lookup()
methods a bit to make them easier to understand.Generic code cleanup: PEP 8,
is
instead of==
for pointers, ...Timings:
All the changes above lead to a modest speed-up:
MonoDict
lookup:Before:
20000 loops, best of 20: 72.7 µs per loop
After:
20000 loops, best of 20: 64.5 µs per loop
TripleDict
lookup:Before:
20000 loops, best of 20: 97.3 µs per loop
After:
20000 loops, best of 20: 87.3 µs per loop
CC: @simon-king-jena @nbruin @tscrim @fchapoton
Component: coercion
Author: Jeroen Demeyer
Branch/Commit:
7c83e05
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/24135
The text was updated successfully, but these errors were encountered: