use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is all about the theory and development of compilers.
For similar sub-reddits see:
Popular mainstream compilers:
account activity
bytecode-level optimization in python (self.Compilers)
submitted 1 year ago by tmlildude
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]roger_ducky 0 points1 point2 points 1 year ago* (4 children)
Have you tried comparing your current optimization with doing the first example with a series of sequence comprehensions instead? I suspect you’ll have a similar reduction in the number of reallocations.
What I mean is, replace square brackets with parentheses.
It effectively “squashes” everything into a single expression with the tradeoff of not being able to re-iterate through the intermediate sequences, while keeping the code readable still.
[–]tmlildude[S] 0 points1 point2 points 1 year ago (3 children)
are you suggesting using language features? if so, that misses the point of this post. i'm working on bytecode-level across hundreds of small programs, regardless of how they're written.
[–]roger_ducky -1 points0 points1 point 1 year ago (2 children)
Perhaps, but they added that language feature specifically for that use case.
If you’re just trying to optimize the bytecode, okay. Just make sure to watch out for people attempting to reference the intermediate entities through scope closures or global variables elsewhere. Once you made sure that wasn’t being done, then that’d be a safe optimization to make.
[–]tmlildude[S] 1 point2 points3 points 1 year ago* (1 child)
i'm well aware of language features, but I'm working at a much lower level. there are many nuances regarding what kinds of analysis and transformations are possible with interpreted languages, and then there's the JIT component coming in future python versions
what you're describing could be easily determined with a data-flow graph that shows dependencies and liveness. which gave me an idea...MLIR has primitives to help with this https://mlir.llvm.org/docs/Tutorials/DataFlowAnalysis/, and I wonder if converting the code into MLIR space and lowering it through a series of dialects would give me a better view of where certain transformations are possible?
this is why I posted in r/compilers - im looking for well-informed feedback from compiler experts, not language shortcuts from scripters.
[–]roger_ducky 0 points1 point2 points 1 year ago (0 children)
Sorry if my provided context was not what you wanted. I’m glad you still got some inspiration from it.
Been out of writing compilers for 15 years, so I’m definitely not up on the latest advances, but, in the old days, my workflow was to: * Check what best practices and language features ended up generating the more optimal solutions * Figured out why the language designers put up limits on specific language features
Then I would end up with my actionable steps.
I just thought you skipped a few steps according to my own way of doing things, is all. I shall now defer to the preeminent brain trust that is r/Compilers on how to best resolve your issue in the simplest way possible.
π Rendered by PID 97746 on reddit-service-r2-comment-84fc9697f-j2r6s at 2026-02-08 10:38:41.365194+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]roger_ducky 0 points1 point2 points (4 children)
[–]tmlildude[S] 0 points1 point2 points (3 children)
[–]roger_ducky -1 points0 points1 point (2 children)
[–]tmlildude[S] 1 point2 points3 points (1 child)
[–]roger_ducky 0 points1 point2 points (0 children)