Live data from Hacker News

Show HN: Nimic – Pure Python as a systems language with AOT compilation

github.com

11–20 of 31 posts

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#11
post #7

The line I'd push on is "valid Python that runs unmodified in CPython." True at the syntax level, but the speedup isn't really coming from Nim as a backend, it comes from how much of Python's dynamism you can pin down at compile time. Refcounting semantics, __getattr__, values that change type at runtime, isinstance-based dispatch, monkeypatching in tests: the moment you statically commit to any of those, you've defi…

True, nimic is a statically typed Python subset without much of its dynamism with the aim to be foremost an efficient systems language. Though in nimic, without using isinstance, the instance-based dispatch is realised via variant types. Yes, emulating the Nim constructions in Python was the hardest part, while making the transpiler was straightforward. Indeed, the AOT compilation leads to great speed-ups for heavy c…

the variant-types-for-dispatch thing is a nice tradeoff, makes sense. honestly the strongest pitch in there is the "write the hot module in nimic instead of dropping to c/rust/cython" angle, which is basically the cython niche. so the question is what nimic adds over cython for that. my guess is dual-mode: a .pyx isn't valid python and won't run under plain cpython, but nimic stays importable and debuggable in cpython and you compile only when you want speed. if that's the edge i'd put it front and center, it's a way sharper sell than "python but fast".

one thing i'd worry about with "runs unmodified in cpython" though: python ints are arbitrary precision and nim's aren't. so the same code can give you a bignum under cpython and a wraparound under the compiled path. how do you handle that, or is matching cpython semantics explicitly a non-goal for the typed subset?

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#12
post #9

nimic is a lightweight pure Python package that emulates Nim types and constructions, making it straightforward to transpile to Nim and compile AOT. Key principle: nimic code is valid Python that runs unmodified in CPython and also transpiles to equivalent Nim code. Because nimic code is just standard Python with type hints and ctypes shims, it is a fully valid CPython script, so you can use the Python REPL during de…

so it is what https://github.com/mypyc/mypyc was supposed to be ... i can just use write my python code add some type hints and it should run faster ... like cython but without learning a new dsl?

Yeah, indeed, I actually read about mypyc a few years ago before starting nimic. Though the goal is very similar, mypyc does not support compilation to a native executable and the performance gains were somehow limited to 2x-4x, as reported in https://sichard.ca/blog/2022/05/compiling-black-with-mypyc-p...

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#13
post #3

Earlier quoted context omitted.

I would start with a human-written README and benchmarks?

Yeh, indeed, the README was mostly generated, though the introduction is largely human-written :-) Is some specific description missing? I can provide more practical code examples directly in README. The benchmarks are mostly on runtime performance I assume?

> Is some specific description missing?

No, the problems are a) you get the same exact AI "voice" that is tedious to keep reading, b) it's verbose and focuses on the wrong things (the whole Module Architecture section doesn't belong there), and c) it's a sign that it's slop and not well tested.

> The benchmarks are mostly on runtime performance I assume?

You tell me! You (or Claude) make performance claims - "aiming to get C-level performance without leaving Python". Does it actually get anywhere near that claim?

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#14
post #8

nimic is a lightweight pure Python package that emulates Nim types and constructions, making it straightforward to transpile to Nim and compile AOT. Key principle: nimic code is valid Python that runs unmodified in CPython and also transpiles to equivalent Nim code. Because nimic code is just standard Python with type hints and ctypes shims, it is a fully valid CPython script, so you can use the Python REPL during de…

So the big advantage of nimic is that code remains valid Python and all valid Python cam be compiled? The transpile to a language that transpiles to C approach is unusual. Downsides of that other than slower compilation?

Not quite "all valid Python." Just to be clear: nimic is a strict, statically typed subset of Python. At this stage, the downside of having Nim as an intermediate step is not really a slower compilation, as Nim compiler is very fast, but more like: debugging executable, might involve line numbers of the intermediate Nim or C source code; the need to install Nim compiler for development; memory management (currently it is ORC/ARC or manual in Nim, no borrow checker yet)

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#17

Earlier quoted context omitted.

Yeh, indeed, the README was mostly generated, though the introduction is largely human-written :-) Is some specific description missing? I can provide more practical code examples directly in README. The benchmarks are mostly on runtime performance I assume?

> Is some specific description missing? No, the problems are a) you get the same exact AI "voice" that is tedious to keep reading, b) it's verbose and focuses on the wrong things (the whole Module Architecture section doesn't belong there), and c) it's a sign that it's slop and not well tested. > The benchmarks are mostly on runtime performance I assume? You tell me! You (or Claude) make performance claims - "aiming…

Fully fair, I'd need to spend more time on the text. The nimic was mostly tested on the raytracer project dima-quant/ndsl_raytracer, and the performance was indeed quite near the C-level.

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#18
post #8

Earlier quoted context omitted.

So the big advantage of nimic is that code remains valid Python and all valid Python cam be compiled? The transpile to a language that transpiles to C approach is unusual. Downsides of that other than slower compilation?

Not quite "all valid Python." Just to be clear: nimic is a strict, statically typed subset of Python. At this stage, the downside of having Nim as an intermediate step is not really a slower compilation, as Nim compiler is very fast, but more like: debugging executable, might involve line numbers of the intermediate Nim or C source code; the need to install Nim compiler for development; memory management (currently i…

Sorry, missed the word "subset"!

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#19
post #7

The line I'd push on is "valid Python that runs unmodified in CPython." True at the syntax level, but the speedup isn't really coming from Nim as a backend, it comes from how much of Python's dynamism you can pin down at compile time. Refcounting semantics, __getattr__, values that change type at runtime, isinstance-based dispatch, monkeypatching in tests: the moment you statically commit to any of those, you've defi…

Curious why your comment below’s got flagged. I personally don’t see any issue with it.

Re: Show HN: Nimic – Pure Python as a systems language with AOT compilation

#20
post #9

nimic is a lightweight pure Python package that emulates Nim types and constructions, making it straightforward to transpile to Nim and compile AOT. Key principle: nimic code is valid Python that runs unmodified in CPython and also transpiles to equivalent Nim code. Because nimic code is just standard Python with type hints and ctypes shims, it is a fully valid CPython script, so you can use the Python REPL during de…

so it is what https://github.com/mypyc/mypyc was supposed to be ... i can just use write my python code add some type hints and it should run faster ... like cython but without learning a new dsl?

cython uses type hints now
Post reply on HN