Open pohly opened 1 week ago
It's an interesting feature. I imagine it'd be most useful for literals and the AST. Is that what you have in mind as well? Or something else?
Yes, exactly that.
In my experience, unique.Make
can be expensive. But if it is done once and the result is used often, it pays off. Using internalized strings might have to be a compile option because the user should decide about this tradeoff.
Feature request checklist
Change
Go 1.23 added support for internalizing strings with a standard API (https://pkg.go.dev/unique). When compiling an expression, the AST could store string constants as
unique.Handle[string]
. Conversion to a normal string could happen on the fly.Example
I'm implementing a custom map with strings as key:
With unique strings, the map becomes more efficient.
Alternatives considered
A normal string extracted from CEL could be turned into a handle before looking it up in a map which uses internalized strings. But that causes overhead during each evaluation which could be moved into the one-time compilation.