Hacker News new | ask | show | jobs
by anon-3988 361 days ago
I am not that intrigued that Python that can call some pre-compiled functions, this is already possible with any language that produces a dynamic library.

The space that I am interested in is execution time compiled programs. A usecase of this is to generate a perfect hash data structure. Say you have a config file that lists out the keywords that you want to find, and then dynamically generate the perfect hash data structure compiled as if those keywords are compile time values (because they are).

Or, if the number of keywords is too small, fallback to a linear search method. All done in compile time without the cost of dynamic dispatch.

Of course, I am talking about numba. But I think it is cursed by the fact that the host language is Python. Imagine if Python is stronger typed, it would open up a whole new scale of optimization.

3 comments

I would rather image CPython being like Common Lisp, Scheme, Raket, Smalltalk, Self compilation model.

Sadly the contenders on the corner get largely ignored, so we need to contend with special cased JIT DSLs, or writing native extensions, as in many cases CPython is only implementation that is available.

Doesn't Mojo already support this in its parameter system? https://docs.modular.com/mojo/manual/parameters/

Jitting like you mentioned is supported by the MAX graph API: https://docs.modular.com/max/tutorials/build-custom-ops. It could have a nicer syntax though to be more like Numba, I think you have an interesting idea there.

> I am not that intrigued that Python that can call some pre-compiled functions, this is already possible with any language that produces a dynamic library.

> The space that I am interested in is execution time compiled programs. A usecase of this is to generate a perfect hash data structure. Say you have a config file that lists out the keywords that you want to find, and then dynamically generate the perfect hash data structure compiled as if those keywords are compile time values (because they are).

I'm not sure I understand you correctly, but these two seem connected. If I were to do what you want to do here in Python I'd create a zig build-lib and use it with ctypes.

Can Zig recompile itself if I change a config in production? I am talking about this

``` python program.py --config <change this> ```

It is basically a recompilation of the whole program at every execution taking into account the config/machine combination.

So if the config contains no keyword for lookup, then the program should be able to be compiled into a noop. Or if the config contains keyword that permits a simple perfect hash algorithm, then it should recompile itself to use that mechanism.

I dont think any of the typical systems programming allows this.