novika-lang / novika

🪱 Novika is a free-form, moldable, interpreted programming language
https://novika-lang.github.io/
MIT License
15 stars 0 forks source link

Make `Entry` and `OpenEntry` a struct? #84

Open homonoidian opened 1 year ago

homonoidian commented 1 year ago

I have no idea whether this would have any effect on performance at all, but it would definitely be entertaining to see. Technically, I think this is possible by storing a reference to the dictionary that holds the entry inside that entry. If I remember correctly, the only reason I created the Entry object at all is (a) for tagging opener/pusher & consequent polymorphic on_open etc., and (b) to save on lookups during submit without having to handwrite custom submit lookup method (in a very naive implementation, we'd have to have two lookups: one to find out whether the entry exists, and another to store).

A tiny benchmark would be nice, will put it here before everything.

homonoidian commented 1 year ago

The thing is actually slower because Crystal's hash methods are clumsy for this particular use case. To make use of the struct entries, we have to first find that struct entry in the dictionary, and then to submit to it, we have to again find it (Hash(K, V)#update and Hash(K, V)#[]=) and only then write.

As with everything, this could be resolved by writing a custom hash table implementation. Maybe, maybe not. I'm not in the mood of doing this -- there are much more interesting Substrate and Tape optimizations coming (hopefully!)