3 ms·
Great, but afaict, it's not a jit. It is using llvm to aot-compile Python code. Decorators are called when their respective functions are compiled, not when the
by bjourne 2y ago
Great, but afaict, it's not a jit. It is using llvm to aot-compile Python code. Decorators are called when their respective functions are compiled, not when they are called.
- deleted 2y ago[deleted]
- dec0dedab0de 2y agoA decorator is run at compile time and it’s output replaces the decorated function. The new replaced function could then have a jit at runtime. I don’t know if that’s what’s happening, but using a decorator doesn’t mean it cant also be a jit.
- masklinn 2y agoFWIW numba at least supports both cases depending how the decorator is used: - if you just `@jit`, it will create a megamorphic function with specialisations generated at runtime - if you pass a signature to `@jit`, it will compile a monomorphic function during loading
- eliben 2y agoJIT is something different people sometimes define in different ways. In this sample, when the function itself is called (not when it's decorated), analysis runs followed by LLVM codegen and execution. The examples in the blog post are minimal, but can be trivially extended to cache the JIT step when needed, specialize on runtime argument types or values, etc. If this isn't JIT, I'm curious to hear what you consider to be JIT?
- willseth 2y agoPython decorators simply wrap the function with decorator defined logic, so while yes that is all evaluated when the Python program is first run, whether or not llvm etc are run then vs when the function is first called is completely up to the implementation, ie anyone implementing a decorator based compiler could choose to run the compilation step at Python compile time or runtime or make it configurable.