Live data from Hacker News

SPy: An interpreter and compiler for a fast statically typed variant of Python

antocuni.eu

111–120 of 133 posts

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#111
post #75

If in the end we can just have .spy on some files that have performance critical functions in them and the rest is just normal python, this could be down right amazing. We recently swapped out mypyc optimised module for a rust implementation to get a 2-6x speed up, and not having to do that would be great.

See my other comment in the thread. I would argue that anything that uses arcane dynamic stuff in python should be renamed to .dpy and the vast majority of the commonly used constructs retain .py

The issue in HN threads like this is that everyone is out to promote their own favorite language or their favorite python framework that uses dynamic stuff. The majoritarian and hacker-ethos of python don't always line up.

Like Chris Lattner was saying on a recent podcast, he wrote much of Swift at home on nights/weekends over 18 months. We need someone like that do this for spy.

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#112

Earlier quoted context omitted.

Where is it? Would love to compare the approach to py2many.

https://github.com/spylang/spy

Py2many would fail to compile dynamic code whereas spy runs it through the interpreter.

Otherwise the internal structure looks similar. Py2many has been around for 10+ years under previous names and has significant test coverage.

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#113
post #91
post #41

Earlier quoted context omitted.

Exactly. That was their worst mistake ever

I agree. I use Beartype to get runtime type checks, but it shouldn’t be necessary. Some support for type checking, whether at byte compile time or runtime, should land upstream.

Never gonna happen - the fundamental premise of the language is duck typing.

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#114
How do you envision SPy's generics evolving to handle something like SQLAlchemy-style query builders, where dynamic introspection is key? Eager for the next posts on the type system and static dispatch—already forking the repo to tinker with that raytracer demo. Thanks for open-sourcing this under Anaconda's wing; it's the kind of ambitious reset Python needs.

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#115

Earlier quoted context omitted.

I have asked about using RPython as a generic standalone language before. I think the official statement is that is was never intended to become one, and it's really a very minimal subset of Python (so basically no existing Python code will run, it would require heavy refactoring or complete rewrite), and it's only specifically those features that they currently need, and it might also be a moving target, and they do…

A general purpose language should be suitable to writing its own compiler. If it's to slow for that, what's the point?

A language can be suitable for writing a compiler, but if there is another language that's 10x faster that's also suitable, then you're losing out on a lot of compilation speed for no reason.

Dog-fooding a language by writing a compiler in it can lead to the designers adding language features to make compiler development easier, even if they detract from the design of the language for the 99% of users who aren't writing a compiler.

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#116
post #52
post #45

It's weird, but the pain of moving to a whole new language seems less than the pain of using one of these language subsets. I guess it might be because of "loss aversion": we dislike losing something we have more the value we put on gaining it. In a new language each newly added feature is a gain, but in a language subset you're always encountering things you would have in the full language. So no matter how good the…

> in a language subset you're always encountering things you would have in the full language Exactly. I once pitched the idea of a Python subset (with a different focus, not performance like SPy), and almost every reaction was "will it support ". For example, a new language can build its own solution for array math, or maybe that's not something its users need. OTOH many consider a Python subset to be unacceptable if…

I think Python is a bit special in this case, as many people tend to use it more like duct tape for connecting different libraries (which often contain compiled and optimized code) rather than a language for doing stuff bottom-up.

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#117
>"During the years there have been many attempts to improve Python speed; generally they fall into two categories:

Implement "full Python". To be able to support all dynamic features and be fast, they usually employ a Just In Time (JIT) compiler.

Examples are PyPy, GraalPy, Pyston, and CPython's own JIT.

Implement a "subset of Python" or "variant of Python", either as an Ahead of Time (AOT) or JIT compiler which is able to produce fast code. The usual approach here is to remove many (if not all) of the dynamic features which make Python hard to compile.

Examples are RPython, Mypyc, Cython and Numba.

The problem of "full Python" JIT compilers is that sometimes they work very well and produce huge speedups, other times they don't produce any speedup at all, or might even introduce slowdowns, or they might use too much memory, or they are slow to "warm up".

The problem of the subset/variant approach is that by removing the dynamic features of Python, you end up with something which does not feel pythonic, and in which many typical and idiomatic Python patterns just don't work. You often end up with "Java with Python syntax" (nothing in particular against Java, but I hope it gives an idea of what I mean)."

Isn't that interesting!

You know what I'd love to see?

A Python compiler that works on a function-by-function basis...

That is, for each function, make the determination if a straight "clean" compilation of the function is possible -- that is, if it doesn't use special Python features that make compilation difficult/challenging/complex/impossible -- or have dependencies on other functions that do...

So if you have a Python function that adds simple integer variables, let's say, then that can be converted to C or Assembler or VM or LLVM or QBE code in a straightforward way, but if a function uses objects and lambdas and higher-level/complex constructs in a way that makes compilation challenging, complex or impossible, then flag those functions (write them out in a log, so the programmer could optionally simplify them, etc.) -- those will continue to be interpreted like they always are...

Yes, some or all of that infrastructure might already exist... I'm just thinking aloud... :-)

>"The first problem is that Python is extremely dynamic. I'm not talking only about dynamic typing, but also about the fact that in a given Python process, the "world" is a moving target and "everything can change at any time" "

(If we had a future language that supported both interpreted and compiled functions, then the interpreter should have the concept of "locked" functions and objects -- that is, once the compiler has compiled something, it's now "locked", and changes (if we want to keep it dynamic) to it mean invoking the compiler again post-change, at runtime... it would be messy, but there could be a hybrid dynamic interpreted yet JIT compiled language... but it would require runtime interaction between the interpreter and compiler... which could be messy, to say the least... and yes, some of that infrastructure might already exist...)

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#119
post #105
post #88

Earlier quoted context omitted.

Have you seen how TruffleRuby makes use of LLVM bitcode, to ship C compiler as well?

I haven't, but not surprised given some of the very aggressive (in a good way) things they've done to address performance. It's impressive. I spoke to Chris Seaton back when it was getting started, and loved many of the things they were doing. Personally I want something leaner, and self-hosting, but that's also why mine is still experimental and wildly incomplete and TruffleRuby works for a lot of things.

Here, I don't know all the details, just remember having seen some talks about this in the past.

It builds on top of this effort, https://medium.com/graalvm/graalvm-llvm-toolchain-f606f995bf

"From Interpreting C Extensions to Compiling Them"

https://eregon.me/blog/assets/research/from-interpreting-c-e...

Re: SPy: An interpreter and compiler for a fast statically typed variant of Python

#120
post #86

Earlier quoted context omitted.

Based on my understanding, Mojo aims to make number crunch computation faster (GPU), while as SPy aims to make generic Python application logic faster. Very similar, but different sweet spots and use cases.

Your understanding of mojo is incomplete. Just visiting their website would have cleared that up.

Taking that on a tangent, there's the seed of a very interesting sci-fi story in a world where visiting a website is sufficient to give people a complete understanding of something.

EDIT: thinking about it some more, I would say that there isn't any real barrier with current technoly to having a relatively small on-device LLM downloading a LoRA file from an arbitrary site to get the AI equivalent of "I know Kung-Fu" - the real issue would be on the safety, security and trust aspects.

Post reply on HN