5 ms·
The author hints at the problem > Don’t count on your operator overloads to work here, though. > by keeping these variables around, debugging is more straight
by chrisseaton 8y ago
The author hints at the problem
> Don’t count on your operator overloads to work here, though.
> by keeping these variables around, debugging is more straightforward
The transformations the author is suggesting are not in general legal. Missing operator overloads and inconsistent debugging states aren’t something to gloss over - they’re showing you your optimisations are just wrong!
You would need a sophisticated deoptimisation system with frame states, like JVMs or V8 has, to make them legal.
The Python compiler isn’t dumb - it’s correct.
- nickysielicki 8y ago+1. I'm reminded of a tweet of yours from a few years back! https://twitter.com/chrisgseaton/status/619885182104043520 https://twitter.com/chrisgseaton/status/619885182104043520 Try doing something like that at compile time.
- TeMPOraL 8y agoCommon Lisp does that for breakfast :).
- bjoli 8y ago... I am not sure I am impressed. The rules for partially evaluating eval are the same for partially evaluating any code. I am just not sure anybody else bothered something like that with eval. Edit: I have seen Guile's optimizer/peval turn 30 lines of messy (to human eyes) code to a single atom result. This is actually rather simple as long as you van reason enough about the code and it has no side effects. The hard part is developing heuristics to not have it impact compile time too much
- chrisseaton 8y ago> I am not sure I am impressed My PhD defence committee was impressed, so that was good enough for me. In Ruby almost no code is refentially transparent so just simple PE is not enough. You need to speculate in some complex ways and writing that to be practical is not easy.
- bjoli 8y agoThen I am impressed :) I don't know enough ruby to know exactly why, though. I am just used to seeing this kind of behaviour in guile, and for guile I don't really see why that would be hard, at least if you have enough visibility. I might have gotten it wrong for guile as well :) sorry to sound so dismissive. I would love to read your thesis!
- hermitdev 8y agoI think it might also be a "lazy" solution to a more complex problem, which this post does not address: Python allows nested functions to, IIRC, an unspecified depth (probably limited by something like stack size). I imagine that that given how Python implements variable lookups, this could be problematic with optimizations in that in the face of nested functions and control paths, it would be very difficult (probably not impossible) to prove they are not used.
- ehsankia 8y agoFrom half way in the 2nd paragraph, it was obvious that the author had been looking at Python all wrong > I wonder if the code I’m writing is putting undue constraints on the bytecode compiler and limiting its options If that's what you're wondering while writing Python, then you probably shouldn't be writing Python.
- fake-name 8y agoOoooor, maybe you like to think about what's actually going on when you write code? I certainly basically mentally execute code to some extent as I write it. Is there a way to program that doesn't do something like that?
- antt 8y agoNobody has any idea what a modern x86 cpu does under the hood because we have no access to the microcode. The only thing you can do is run your code and get an empirical answer to the question 'Is it fast enough'.
- firethief 8y agoCompilers almost never emit instructions that are microcoded on any modern processor
- codetrotter 8y agoPlease explain what you mean. The microcode is the “firmware” of sorts of the CPU. What instructions we tell the CPU to execute and what the CPU decides to actually do to achieve the same result you are asking for can be different. What do you mean by the instructions not being microcoded?
- imtringued 8y agoThere is no rule that every instruction has to be implemented with microcode. Simple instructions like adding two numbers don't need it. Microcode is generally used for more complicated instructions, often those with a variable number of cycles. They are also usually not the fastest way to achieve a result.
- sametmax 8y agoDumb was not used in a derrogative way in this article. As a long time Pythonista, I find the article quite balanced actually.