Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?



> 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.


> 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.


Isn'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.


I 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.


>but are we really optimizing for bad code?

Yes




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: