3 ms·
Is there any reason the compiler can't just emit optimized code for both the string and int cases?
by lgas 10y ago
Is there any reason the compiler can't just emit optimized code for both the string and int cases?
- eropple 10y agoYou're going to need to bias in one direction or another. If you can safely inline assumptions regarding the int into the hot path that exists, with a consciously slower bail-out path if it's not an integer. Now consider a situation where `x` is probably an integer--but can be a string or null. We're rapidly getting to a situation where this is going to be puffy code that is hard to constrain to an effective hot path without running the code, yeah? Profile-guided optimization seeks to do this for compiled languages like C++, but you also have a boatload more data to do it with. And, y'know. You're profiling the application. You're running it.