You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
func (d deviceAttributeDomains) Contains(index ref.Val) ref.Val {
strKey, ok := index.ConvertToType(types.UniqueStringType).Value().(unique.Handle[string])
if !ok {
return types.False
}
_, ok = d[strKey]
return types.Bool(ok)
}
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: