back

by tobr·7y ago·view on hn ↗
Can eval ever increase performance? I’m thinking that for some types of abstractions you can end up with highly nested, indirect calls, and if you can instead generate new code as needed, maybe it could speed things up? Are there any mainstream examples of this?
4 comments
I think the Python falcon web server uses eval to produce direct python that executes routing code at run time. I don't have any reason to think it can't be beat, but it is relatively fast for something done in Python.

More generally, generating code is used for a lot of regex engines, though it may happen before runtime.

This looks like a compilation step. If you cannot have your language implementation generate some kind of optimized code statically, you can do it yourself dynamically.
Python uses/used eval for namedtuple at least in part for performance.
Used. Raymond revised the implementation.