News for hackers. Stuff that matters.
Re:Strings Just Got Faster by delusional on Friday May 02, 2025 @06:41PM (#43875221)
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?

Re:Strings Just Got Faster by koolba on Friday May 02, 2025 @08:37PM (#43875899)
> 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.

Re:Strings Just Got Faster by delusional on Saturday May 03, 2025 @04:33AM (#43877660)
> 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.

Re:Strings Just Got Faster by f33d5173 on Saturday May 03, 2025 @01:28AM (#43877054)
>but are we really optimizing for bad code?

Yes

Re:Strings Just Got Faster by gf000 on Saturday May 03, 2025 @07:19AM (#43878316)
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.
Re:Strings Just Got Faster by joejev on Saturday May 03, 2025 @12:56PM (#43880379)
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.