Hacker News
How to make a fast dynamic language interpreter
pansa2
|next
[-]
Unlike the Zef article, which describes implementation techniques, the Wren page also shows ways in which language design can contribute to performance.
In particular, Wren gives up dynamic object shapes, which enables copy-down inheritance and substantially simplifies (and hence accelerates) method lookup. Personally I think that’s a good trade-off - how often have you really needed to add a method to a class after construction?
versteegen
|root
|parent
|next
[-]
psychoslave
|root
|parent
|previous
[-]
On the other side, having a type holding a closed set of applicable functions is somehow questioning.
There are languages out there that allows to define arbitrary functions and then use them as a methods with dot notation on any variable matching the type of the first argument, including Nim (with macros), Scala (with implicit classes and type classes), Kotlin (with extension functions) and Rust (with traits).
jiusanzhou
|next
|previous
[-]
Someone
|root
|parent
[-]
I’m basing that on the 1.6% improvement they got on speeding up sqrt. That surprised me, because, to get such an improvement, the benchmark must spend over 1.6% of its time in there, to start with.
Looking in the git repo, it seems that did happen in the nbody simulation (https://github.com/pizlonator/zef/blob/master/ScriptBench/nb...).
tnelsond4
|next
|previous
[-]
catlifeonmars
|next
|previous
[-]
grg0
|next
|previous
[-]
I also like how, according to Github, the repo is 99.7% HTML and 0.3% C++. A testament to the interpreter's size, I guess?
injidup
|next
|previous
[-]
valorzard
|next
|previous
[-]
tiffanyh
|next
|previous
[-]
pizlonator
|root
|parent
[-]
There are many runtimes that I could have included but didn’t.
Also, it’s quite impressive how much faster PUC Lua is than QuickJS and Python
raincole
|root
|parent
|next
[-]
(I suppose the quick in QuickJS means "quick for a pure interpreter without JIT compilation or something...)
zephen
|root
|parent
|previous
[-]
Python's execution time is mostly spent looking up stuff. I don't think lua is quite as dynamic.
pizlonator
|root
|parent
[-]
zephen
|root
|parent
|previous
[-]
But in Python, everything is an object, which is why, as I said, it spends much of its time looking things up. And things like bindings for closures are late, so that's more lookups as well.
In lua, many things aren't objects, and, for example, you can add two numbers without looking anything up. Another issue, of course, when you do that, is that you could conceivably overflow an integer, but that can't happen in Python either.
The Python interpreter has some fast paths for specific object types, but it is really limited in the optimizations it can do, because there simply aren't any unboxed types.
psychoslave
|root
|parent
[-]
zelphirkalt
|root
|parent
|next
[-]
gdwatson
|root
|parent
[-]
This feels more like a party trick than anything. But it does represent a deep commitment to founding the whole language on object orientation, even when it seems silly to folks like me.
zephen
|root
|parent
|previous
[-]
boulos
|next
|previous
[-]
pizlonator
|root
|parent
[-]
It was materially useful in this project.
- Caught multiple memory safety issues in a nice deterministic way, so designing the object model was easier than it would have been otherwise.
- C++ with accurate GC is a really great programming model. I feel like it speeds me up by 1.5x relative to normal C++, and maybe like 1.2x relative to other GC’d languages (because C++’s APIs are so rich and the lambdas/templates and class system is so mature).
But I’m biased in multiple ways
- I made Fil-C++
- I’ve been programming in C++ for like 35ish years now
vlovich123
|root
|parent
[-]
pizlonator
|root
|parent
[-]
> happen to know C++ really well
That’s my bias yeah. But C++ is good for more than just perf. If you need access to low level APIs, or libraries that happen to be exposed as C/C++ API, or you need good support for dynamic linking and separate compilation - then C++ (or C) are a great choice
vlovich123
|root
|parent
[-]
The syntax and ownership rules can take some getting used to but after doing it I start to wonder how I ever enjoyed the masochism of the rule of 5 magic incantation that no one else ever followed and writing the class definition twice. + the language gaining complexity constantly without ever paying back tech debt or solving real problems.