4 ms·
I would love to see some benchmarks that demonstrate the impact of the more optimized representation. I found that despite some possibly sub-optimal performance
by sizediterable 5y ago
I would love to see some benchmarks that demonstrate the impact of the more optimized representation. I found that despite some possibly sub-optimal performance trade-offs in favor of productivity in my own hobby interpreter, it can still do much better than Python and Wren in some micro-benchmarks that I performed (naive sum in a loop and naive fibonacci implementation). Python was no surprise since PyObjects are relatively "fat" [0], but Wren was created by the author of Crafting Interpreters (mentioned in the article) so I expected a bit better. My representation ended up looking something like:
enum Value {
Unit,
False,
True,
Integer(isize),
Float(FloatSize),
String(Rc<str>),
Closure(Rc<Closure>),
Tuple(Rc<[Value]>),
}
Unfortunately since I'm depending on reference-counting, it can't implement `Copy` which I suspect is where I'm currently losing significant performance. For values embedded in bytecode instructions I can cheat and copy anyway since only the non-refcounted ones are allowed in them.
[0] https://github.com/python/cpython/blob/main/Include/object.h#L105-L109 https://github.com/python/cpython/blob/main/Include/object.h...
- mamcx 5y agoYeah, I wonder the same. I struggle a lot early on my lang with this (also: Wanna have 2d vectors) and eventually get a enum alike yours (but the Rc<str>, Rc<Closure>, Rc<[Value]> intrigue me!).
- emteycz 5y agoHow about turning Value into MemoryCell and handling references outside of it?
- sizediterable 5y agoIt's something I'm willing to explore once I have more comprehensive benchmarks. Right now the ones I have are significantly weighted on integer operations that I think will be hurt by the additional pointer indirection. Once my benchmark suite is less biased I can make a more holistic decision about the trade-offs.
- celeritascelery 5y agoI plan at some point to implement some benchmarks to test exactly that. I have the feeling that the gain is not going to be as significant as I initially expected. Rust is pretty good at optimizing fat pointers. Though another advantages to word-width objects is that they can generally be used in atomics, whereas sizes greater then a word usually can't. Do you have a link to your hobby interpreter? I would love to take a look at it.