-
Notifications
You must be signed in to change notification settings - Fork 0
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
Reduce our dependencies #20
Comments
The tox 2.7 environment currently contains 76 libraries. I've released zope.mimetype 2.3.0 which adds a zope.file still pulls in zope.formlib. It needs the same treatment. |
Once I clean up zope.file, zope.container still pulls in zope.publisher and zope.browser. But I think maybe that's the last of it. |
zope.traversing also pulls in zope.publisher.
|
And...untangling zope.publisher from zope.traversing would be a substantial undertaking. That may be where we leave that part of it for now. |
Three points about that. First, The second is that including an ABC in your Consider the simplest possible positive In [34]: %timeit isinstance({}, dict)
The slowest run took 7.65 times longer than the fastest.
This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 374 ns per loop (I'll elide that warning about intermediate results from now on. They're all about that order of magnitude.) The longer the list of types you check gets, the more time it takes, even if the first item in the list is definitely a match. In [42]: %timeit isinstance({}, (dict, persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree))
1000000 loops, best of 3: 651 ns per loop
In [43]: %timeit isinstance({}, (dict, persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree, int, long, str))
1000000 loops, best of 3: 807 ns per loop
In [44]: %timeit isinstance({}, (dict, persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree, int, long, str, unicode, float))
1000000 loops, best of 3: 862 ns per loop
In [45]: %timeit isinstance({}, (dict, persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree, int, long, str, unicode, float, list, type))
1000000 loops, best of 3: 934 ns per loop
In [46]: %timeit isinstance({}, (dict, persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree, int, long, str, unicode, float, list, type, collections.Mapping))
1000000 loops, best of 3: 980 ns per loop That looks bad until you realize that much of that time is spent constructing the tuple to pass in. If you use a constant tuple (as we do), it stays closer to the original time: In [49]: t = (dict, persistent.mapping.PersistentMapping, BTrees.OOBTree.OOBTree,
int, long, str, unicode, float, list, type, collections.Mapping)
In [50]: %timeit isinstance({}, t)
1000000 loops, best of 3: 411 ns per loop Now, a positive check for a dict against a single In [57]: t = collections.Mapping
In [58]: %timeit isinstance({}, t)
1000000 loops, best of 3: 1.47 µs per loop And if we don't specifically include the In [59]: t = (persistent.mapping.PersistentMapping, BTrees.OOBTree.OOBTree,
...: int, long, str, unicode, float, list, type, collections.Mapping)
In [60]: %timeit isinstance({}, t)
100000 loops, best of 3: 2.21 µs per loop A trivial negative check for an ABC is around twice the price of a trivial positive check: In [51]: %timeit isinstance(1, collections.Mapping)
100000 loops, best of 3: 2.5 µs per loop But an expensive negative check against a long list ending in an ABC isn't that bad, relatively speaking: In [63]: t = (persistent.mapping.PersistentMapping, BTrees.OOBTree.OOBTree,
...: str, unicode, float, list, type, collections.Mapping)
In [64]: isinstance(1, t)
Out[64]: False
In [65]: %timeit isinstance(1, t)
100000 loops, best of 3: 2.97 µs per loop So, basically, order matters, and a long list, so long as its constant, doesn't hurt that much and may be better in performance sensitive code than an ABC. We're going to have a dependency on BTrees as long as we have a dependency on ZODB, so it might as well stay in the list. The final point is that we're currently not very optimal. Look at how we currently define SEQUENCE_TYPES = (persistent.list.PersistentList,
collections.Set,
list,
tuple)
MAPPING_TYPES = (persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree,
collections.Mapping) We have an ABC in the list of sequence types before the basic types And now, just for the fun of it, lets look at how two of our longest examples in CPython (2.21us, 2.5us, and 2.97 us, respectively) do in PyPy (watch those caching warnings!): In [3]: t = (persistent.mapping.PersistentMapping, BTrees.OOBTree.OOBTree,
...: int, long, str, unicode, float, list, type, collections.Mapping)
In [4]: %timeit isinstance({}, t)
The slowest run took 122.02 times longer than the fastest.
This could mean that an intermediate result is being cached.
1000000 loops, best of 7: 236 ns per loop
In [5]: %timeit isinstance(1, collections.Mapping)
The slowest run took 921.64 times longer than the fastest.
This could mean that an intermediate result is being cached.
1000000 loops, best of 7: 273 ns per loop
In [6]: t = (persistent.mapping.PersistentMapping, BTrees.OOBTree.OOBTree,
...: str, unicode, float, list, type, collections.Mapping)
In [7]: %timeit isinstance(1, t)
The slowest run took 34.06 times longer than the fastest.
This could mean that an intermediate result is being cached.
1000000 loops, best of 7: 294 ns per loop So about 10x faster than CPython on the microbenchmark when the JIT kicks in. |
Do we need ZODB? it seems to be only needed to get the external oid. |
Off hand, I don’t remember, but i would guess we would want that for IConnection. It seems to me external oids are a somewhat important part of this package. |
We have a massive dependency tree:
We can't possibly really need all of those in the core.
For example, we only depend on
zope.preference
to be able to list it in configure.zcml. That's probably not our job.For another example, we only depend on BTrees to be able to include OOBTree.OOBTree in
isinstance(thing, MAPPING_TYPES)
call. Shouldn't that just beisinstance(thing, collections.Mapping)
(and allow the user to register mapping types with the collections.Mapping ABC, as it is intended for.The text was updated successfully, but these errors were encountered: