Lucen - Parallelize Python loops with comment pragmas
Show HN: Lucen a Python compiler that parallelizes for-loops via comment pragmas
Lucen is a revolutionary source-to-source compiler for Python that automatically parallelizes for-loops simply by adding two comment pragmas. Unlike traditional frameworks requiring complex rewrites, Lucen guarantees bit-identical results to sequential execution, ensuring no incorrect answers, no race conditions, and no need for manual lock management. It intelligently analyzes code to parallelize only safe and profitable loops, falling back to sequential execution with clear reports if risks are detected. With support for CPython 3.9 to 3.14 and PyPy, developers can achieve significant speedups, such as 3.8x faster performance on CPU-bound tasks, without altering their existing codebase structure or risking data integrity.
Lucen never produces an incorrect result.
- gabrielsroka
Not very Pythonic
for i in range(len(records)):
scores[i] = score(records[i])
Better
for i, record in enumerate(records):
scores[i] = score(record)
Best
scores = [score(record) for record in records]
Raymond Hettinger (Python core dev): https://gist.github.com/bespokoid/205efd91546ddb16b210678830...
- zbentley
This code seems to be fairly pervasively AI-written (both structurally/syntacticly, with many additional AI verbosity tells in the documentation, and going by the commit history).
That's a problem for me, given what this library does: arbitrary transformations of Python code at load time. The fragility, security risk, and complexity added by basically writing a subdialect of Python with new semantics is something I'd like to see more human attention on and maturity of before I consider using it. There are times when AI smell doesn't concern me much when deciding whether or not to use someone's code. This isn't one of those times.
- peterabbitcook
I think I’m a little skeptical.
#pragma is a real keyword in C but # is just a comment in python - why not use a pythonic @decorator?
Vendoring a library like this into an app seems like a lot more toil than just writing the native multiprocessing python code, or using something built for number crunching like arrayfire or numpy