5 ms·
Profiling CPython at Instagram (2017)
- yedpodtrzitko 8y agopublished at November 2017
- medecau 8y agoThought-bleach for yesterday's post?
- mcenedella 8y agoWhat’s a thought-bleach?
- dmoreno 8y ago> This suggested techniques to eliminate loads and stores (e.g. switching to a register based bytecode) would be an effective optimization. Did anybody try anything in these line of work?
- jashmatthews 8y agoThere's an experimental branch for Ruby: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch Dalvik also uses a register-based bytecode. The early versions of Android needed a more efficient interpreter. Dan Bornstein's talk: https://www.youtube.com/watch?v=ptjedOZEXPM https://www.youtube.com/watch?v=ptjedOZEXPM A classic paper on Register vs Stack VMs: https://www.usenix.org/legacy/events/vee05/full_papers/p153-yunhe.pdf https://www.usenix.org/legacy/events/vee05/full_papers/p153-...
- raverbashing 8y agoWell, you can (kinda) do that if you have "direct access" to positions in the stack, so for example, say `add s[0],s[3]` (I think x87 had something like that)
- tyingq 8y agoThe Perl6 VMs (Parrot, MoarVM) are register based.
- mschaef 8y agoI believe Lua is as well.
- sandGorgon 8y agothis is a very interesting talk around the same topic - https://lwn.net/Articles/754163/ https://lwn.net/Articles/754163/ > But Shapiro may not be aware that the Python core developers have often preferred simpler, more understandable code that is easier to read and follow, over more complex algorithms and data structures in the interpreter. Some performance may well have been sacrificed for readability. > Mark Shannon said that Python 3.7 has added a feature that should provide a similar boost as the method-lookup caching used in the experiment. Shapiro said he had looked at those changes but still believed his proposed mechanism would provide more benefit. Attribute lookup still requires five lookups in CPython, while it is only one lookup in the experimental version. Shannon did not sound entirely convinced of that, however.
- Alex3917 8y agoIs there any Python library for profiling or optimizing regex? E.g. for a given set of fixture data, see which order things inside each group should be in to get the fastest test suite times while everything still passes.
- valarauca1 8y agoOptimal layout of a NFA-Regex is (I assume) an Hard academic Problem. Which means a library likely won't just be able to "do it for you". The CS-Fundamentals that underscore (Python, Perl, PRCE, and Java regexes) are the same. So this longer article may help: https://www.javaworld.com/article/2077757/core-java/optimizing-regular-expressions-in-java.html https://www.javaworld.com/article/2077757/core-java/optimizi... as while the syntax of the regex may change, the side effects and performance implications of the individual operators will not.
- sciurus 8y agoThis gives instagram ideas for how to improve the python interpreter for their workload. If instead you're interested in profiling to look for ways to improve your python code, check out https://github.com/uber/pyflame https://github.com/uber/pyflame or https://github.com/benfred/py-spy https://github.com/benfred/py-spy
- gnufx 8y agoTo repeat https://news.ycombinator.com/item?id=17929621 https://news.ycombinator.com/item?id=17929621, there is Python support in several comprehensive performance tools with better visualization/analysis functions than flame graphs. I don't know how well the Python-specific instrumentation compares with the above, but it would be worth working on, if necessary, for what the tools provide generally..
- datavirtue 8y agoSo stop using functions...got it.
- nomel 8y agoThe Python Performance Tips [1] basically says this, along with many other helpful hints when trying to squeeze performance. They all boil down to: In a tight loop, don't do anything that triggers a lookup or function call. [1] https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Data_Aggregation https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Dat...
- gnufx 8y agoWhen Python first appeared, the things I remember striking dynamic languages people were strange scoping, no "proper" GC, but particularly being designed to prevent efficient implementation. It was an opportunity to get research computing off Tcl, though.
- posharma 8y agoWhy not just use Java/C++?
- xapata 8y ago"Our most common success story starts with a Java or C++ project slated to take a team of 3-5 developers somewhere between 2-6 months, and ends with a single motivated developer completing the project in 2-6 weeks (or hours, for that matter)." https://www.paypal-engineering.com/2014/12/10/10-myths-of-enterprise-python/ https://www.paypal-engineering.com/2014/12/10/10-myths-of-en...
- typon 8y agoDifferent tools for different jobs.
- munificent 8y ago> Roughly 85% of LOAD_ATTRs occured at monomorphic sites; This observation and the accompanying graph are, I think, the "generational hypothesis" equivalent to static types. The generational hypothesis says most objects are either very short-lived or long-lived and modern generation GCs very effectively optimize for that fact. A particularly pragmatic way to look at static types is that they optimize for monomorphic calls at the expense of polymorphic calls. For the latter, they require you to manually define interfaces, virtual methods, or some other explicit dynamism. In return, monomorphic calls are much faster. The 85% number is an indication that that's a good optimization, as long as the other 15% aren't too hard to handle in your statically-typed language.
- xapata 8y agoOr you can just do what Python 3.7 implemented (and Instagram seems to have separately implemented) -- cache attribute lookups and invalidate the cache if necessary. [0] The GC optimization, well, that'll probably be left up to other interpreters. [0] "Mark Shannon said that Python 3.7 has added a feature that should provide a similar boost as the method-lookup caching used in the experiment. Shapiro said he had looked at those changes but still believed his proposed mechanism would provide more benefit. Attribute lookup still requires five lookups in CPython, while it is only one lookup in the experimental version. Shannon did not sound entirely convinced of that, however." https://lwn.net/Articles/754163/ https://lwn.net/Articles/754163/