3 ms·
By the way, compiling a data structure to a lookup function is a very clever trick, and fortunately something Clojure makes easy. It reminds me of how old-schoo
by lukev 16y ago
By the way, compiling a data structure to a lookup function is a very clever trick, and fortunately something Clojure makes easy. It reminds me of how old-school assembly programmers would blur the lines between code and data for better performance. Only this is more structured and easier to manage.
There are a couple of drawbacks, though:
1. It really only works for read-only data. Generating a new lookup-fn is a pretty expensive operation. I don't think I could use this for data that changed at all.
2. Compiled code uses permgen space and isn't garbage collected as easily. If you make extensive use of this technique, especially with large maps, it'd be really easy to blow your permgen space.