-
Notifications
You must be signed in to change notification settings - Fork 19
Speedup with_init #9
Conversation
Some numbers: https://gist.github.com/hynek/056e0d206bc474af4b94 |
→
|
Personally, without this optimization (or one like it), the point of characteristic is somewhat obviated for me. It's annoying to type As far as characteristic is supposed to be promoting this approach and making it easier to declare objects, I strongly suspect that the average Python programmer will immediately give up on it when they learn that it's going to cause a 30% slowdown for object construction throughout their codebase. That's not to say that @exarkun's concern is unwarranted; it would be good to make |
Thank you for your support glyph. I see it exactly your way; if I want to promote many small objects, it should be as fast as possible and pre-writing optimal code seems like exactly the way to go. Would you consider the linecache thing a blocker for this PR? I’ve never used it, so help would be appreciated. |
Personally I wouldn't consider it a blocker but then again I don't spend a lot of time staring at inscrutable state in PDB, and I recognize that this is a privilege bought with the time of people who do ;-). I'll have a crack at getting code-inspection tools like debuggers or profilers to do something reasonable with this in the coming week. Please feel free to pester me; specifically, I think I can make some time on Wednesday for this. |
Good, I’m merging it now with the loose prospect of making it nicer later. Stepping through looks like this btw:
It’s not pretty but there’s worse things in the world if we don’t get it done. Would changing |
This has little or nothing to do with my concern. Losing the ability to coherently step through the source code is my concern. Not really. The first time I have to debug this kind of code I'll probably switch away from characteristic. Having to type the |
That would be a pity because the init-autogen is in there more or less for you. Let’s see if glyph gets that pdb-able. |
Well, the If you can coherently step through the generated code in PDB with a source listing, would that address your concern? Or is any level of automated code generation unacceptable? |
I’ve rebased it for the new factory code; making it jp-compatible would be very much appreciated now (since I have no idea how). FWIW, this is the last blocker for 14.0. |
Let's be specific: "jp-compatibility" is defined as having comprehensible behavior when you step through the source code. A little asciicast of some sensible single-stepping through PDB or PUDB where you can tell when each attribute is set should demonstrate the proof of concept. In the absence of further feedback from @exarkun I am going to assume that the major missing piece here is the absence of any source listing in pdb, because that's where you can't tell what's going on when single-stepping through the code (in other words, that's the feature that would be good enough for me). Replacing |
Yup, that’s what I understood too. FWIW, the script is already accessible within |
FWIW this needs another heavy rebase but I’m not going to do it myself. |
1ccc7cd
to
a2be970
Compare
db0179d
to
6c18e80
Compare
Aaand here we go. I have rebased once more and am curious what y’all say. The speedups are pretty significant: https://gist.github.com/hynek/76b2536c99289ba3e3b2 It’s still noticeably slower than hand-crafted simple version but it should open the doors for further optimizations in the future. |
Side-stepping doesn't work anymore since we don't use setattr anymore.
This does not break any of the test suites of my projects using characteristic. |
@hynek - sorry I never got around to this. I'm extremely grateful that you made the time. Thank you for enhancing this important optimization with this arguably even more important debuggability and readability feature :). |
Speedup with_init Code generation is now used to create the actual initializer. This is is much faster already and opens up opportunities for even more optimizations in the future.
Since I’ve got multiple feedback that nothing breaks, I’m merging it now. Thanks to everyone for their cooperation! |
The current version may be Pythonic but it‘s quite ineffective.
Since I like having a lot of classes with a lot of instances, I want it to be as fast as possible.
Let’s introduct some dark arts and create the initializer dynamically!