[issue32346] Speed up slot lookup for class creation

2018-01-15 Thread Antoine Pitrou
Change by Antoine Pitrou : -- status: pending -> closed ___ Python tracker ___ ___

[issue32346] Speed up slot lookup for class creation

2018-01-13 Thread Antoine Pitrou
Antoine Pitrou added the comment: I think that Inada is right: there's too much impact on memory consumption and garbage collection to call this an optimization. Serhiy suggested removing the cache. But, once you remove the cache, you're going to iterate on all values of all

[issue32346] Speed up slot lookup for class creation

2018-01-12 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Since benchgcclasses.py doesn't creates dunder methods, cache doesn't have GC-tracked tuples, and ref cycles. Hmm, you're right, thank you. I can also reproduce your numbers here (using benchgcclasses2.py). There's definitely an impact.

[issue32346] Speed up slot lookup for class creation

2018-01-12 Thread INADA Naoki
INADA Naoki added the comment: > Note this is really a worst-case benchmark: lots of classes, no methods, no > user data beside the classes. Since benchgcclasses.py doesn't creates dunder methods, cache doesn't have GC-tracked tuples, and ref cycles.

[issue32346] Speed up slot lookup for class creation

2018-01-12 Thread Antoine Pitrou
Antoine Pitrou added the comment: Serhiy: > The relative speed up looks nice. But it is just few microseconds per class. > You have to create many thousands of classes to gain a significant fraction > of second. This work started with your message in

[issue32346] Speed up slot lookup for class creation

2018-01-12 Thread Antoine Pitrou
Antoine Pitrou added the comment: Here is a simple script creating 1 classes (a large number, but perhaps not out of sight for a large application importing a lot of libraries (*)). (*) see the experiment I did in

[issue32346] Speed up slot lookup for class creation

2018-01-12 Thread INADA Naoki
INADA Naoki added the comment: As my understand, this patch creates cache for all classe, not only for parent classes. Caches may has much tuples, and they are GC tracked because they contains function descriptors. And they actually creates reference cycles. Am I

[issue32346] Speed up slot lookup for class creation

2018-01-11 Thread Antoine Pitrou
Antoine Pitrou added the comment: Le 11/01/2018 à 20:25, Serhiy Storchaka a écrit : > > I'm not sure how this caching works when change the parent class after > creating the child class. The caching is invalidated at the same place the method cache is invalidated. > Without

[issue32346] Speed up slot lookup for class creation

2018-01-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The relative speed up looks nice. But it is just few microseconds per class. You have to create many thousands of classes to gain a significant fraction of second. And the complexity added by this patch is not tiny. I'm not

[issue32346] Speed up slot lookup for class creation

2018-01-04 Thread Antoine Pitrou
Antoine Pitrou added the comment: > While I like faster startup time, I don't know 4% speed up is worth enough > for this complexity. There's no magic bullet that I know of to reduce startup time by a large amount. So we're left with optimizing progressively. For

[issue32346] Speed up slot lookup for class creation

2018-01-04 Thread INADA Naoki
INADA Naoki added the comment: In my environment, python -X importtime -c 'import asyncio' speed up from 53.2ms to 51ms. While I like faster startup time, I don't know 4% speed up is worth enough for this complexity. -- ___

[issue32346] Speed up slot lookup for class creation

2018-01-04 Thread Antoine Pitrou
Antoine Pitrou added the comment: I see, so I should be able to reuse tp_cache for this PR. -- ___ Python tracker ___

[issue32346] Speed up slot lookup for class creation

2018-01-03 Thread Guido van Rossum
Guido van Rossum added the comment: I don't recall what I meant to use tp_cache for, but everything I can find about it says it's unused, so let's kill it if we can. I guess the ABI requires that we keep the slot around until we find a new use for it? --

[issue32346] Speed up slot lookup for class creation

2018-01-03 Thread Antoine Pitrou
Antoine Pitrou added the comment: What exactly is tp_cache? Apparently it was added by Guido in https://github.com/python/cpython/commit/687ae00460da9cac04eb1ba8f6f5ab4db25fbfc2 but never used (at least officially). commit 687ae00460da9cac04eb1ba8f6f5ab4db25fbfc2 Author:

[issue32346] Speed up slot lookup for class creation

2018-01-03 Thread INADA Naoki
INADA Naoki added the comment: How about reusing tp_cache instead of adding new slot? -- ___ Python tracker ___

[issue32346] Speed up slot lookup for class creation

2018-01-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: ./python -m timeit -- "class A: pass" - before: 6.63 usec per loop - after: 5.41 usec per loop ./python -m timeit -s "class A: pass" -- "class B(A): pass" - before: 7.04 usec per loop - after: 4.91 usec per loop ./python -m

[issue32346] Speed up slot lookup for class creation

2017-12-21 Thread Antoine Pitrou
Antoine Pitrou added the comment: I don't really understand your proposal, so it's hard to answer :-) Perhaps you can try to implement it so that we can compare? -- ___ Python tracker

[issue32346] Speed up slot lookup for class creation

2017-12-21 Thread INADA Naoki
INADA Naoki added the comment: New slot is really required? My idea is: * Copy slots from MRO * Iterate namespace dict and override slots if dunder is defined Is it impossible or harder than my thought? -- nosy: +inada.naoki

[issue32346] Speed up slot lookup for class creation

2017-12-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: Yes... The patch itself is not very complex, but you have to dive into the intricacies of typeobject.c to understand it :-/ -- ___ Python tracker

[issue32346] Speed up slot lookup for class creation

2017-12-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Due to its complexity it will take a time to make a review of this patch. -- ___ Python tracker

[issue32346] Speed up slot lookup for class creation

2017-12-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: Updated benchmarks against git master (and using pyperf): - before: $ ./env-orig/bin/pyperf timeit -q "class Test: pass" Mean +- std dev: 8.89 us +- 0.09 us $ ./env-orig/bin/pyperf timeit -q -s "from logging import Logger" "class

[issue32346] Speed up slot lookup for class creation

2017-12-16 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- priority: normal -> low ___ Python tracker ___

[issue32346] Speed up slot lookup for class creation

2017-12-16 Thread Antoine Pitrou
Antoine Pitrou added the comment: Some micro-benchmarks: $ ./python -m timeit "class Test: pass" - before: 8.84 usec per loop - after: 7.03 usec per loop $ ./python -m timeit "class Test(tuple): pass" - before: 10.1 usec per loop - after: 8.4 usec per loop $ ./python -m

[issue32346] Speed up slot lookup for class creation

2017-12-16 Thread Antoine Pitrou
Change by Antoine Pitrou : -- stage: -> patch review ___ Python tracker ___ ___

[issue32346] Speed up slot lookup for class creation

2017-12-16 Thread Antoine Pitrou
Antoine Pitrou added the comment: I posted https://github.com/python/cpython/pull/4902 for this. This approach has two drawbacks: - uses an additional tp_ slot (and a corresponding TPFLAGS) - adds a bit of code complexity (but quite localized) -- stage: patch review ->

[issue32346] Speed up slot lookup for class creation

2017-12-16 Thread Antoine Pitrou
Change by Antoine Pitrou : -- keywords: +patch pull_requests: +4797 stage: -> patch review ___ Python tracker ___

[issue32346] Speed up slot lookup for class creation

2017-12-16 Thread Antoine Pitrou
New submission from Antoine Pitrou : As mentioned in https://mail.python.org/pipermail/python-dev/2017-December/151298.html, slot lookup can take 75 to 80% of the runtime when creating a new class. This was slightly improved in https://bugs.python.org/issue31336 but we're