4 ms·
The example is entirely unconvincing. Why would you store those calls in a map and not just a variable? Even if the map is crucial for some reason, why not hav
by delusional 1y ago
The example is entirely unconvincing. Why would you store those calls in a map and not just a variable?
Even if the map is crucial for some reason, why not have the map take a simple value (like a unint64) and require the caller to convert their string into a slot before looking up the function pointer. That way the cost to exchange the string becomes obvious to the reader of the code.
I struggle to find a use case where this would optimize good code. I can think of plenty of bad code usecases, but are we really optimizing for bad code?
- koolba 1y ago> I struggle to find a use case where this would optimize good code. I can think of plenty of bad code usecases, but are we really optimizing for bad code? The most common such usage in modern web programming is storing and retrieving a map of HTTP headers, parsed query parameters, or deserialized POST bodies. Every single web app, which arguably is most apps, would take advantage of this.
- delusional 1y ago> storing and retrieving a map of HTTP headers. I dont have the profiling data for this, so this is pure theoretical speculation. At the time you're shoving http headers, which is dynamic data that will have to be read at runtime, into a heap allocated datastructures inside the request handling. It kinda feel like doing a little xor on your characters is a trivial computation. I don't envision this making any meaningful difference to those HTTP handlers, because they were written without regard for perfomance in the first place.
- f33d5173 1y ago>but are we really optimizing for bad code? Yes
- gf000 1y agoI think it's a pretty myopic view - this exact case might not appear as is, but might readily appear in completely sane and common code after inlining a few things and other optimisations.
- joejev 1y agoIsn't the entire point of an optimizer to convert "bad code" into "good code"? Your proposed solution is to have the user manually implement a hash table, but if you have a good optimizer, users can focus on writing clear code without bugs or logic errors and let the machine turn that into efficient code.