stringToEnum
: Sort enum fields before inline for
#17527
Labels
contributor friendly
This issue is limited in scope and/or knowledge of Zig internals.
optimization
standard library
This issue involves writing Zig code for the standard library.
As discovered in Vexu/arocc#524 (Vexu/arocc#524 (comment)),
stringToEnum
could have considerably better codegen for large enums if it were sorted by field length before theinline for
:zig/lib/std/meta.zig
Lines 41 to 46 in a126afa
Here's a benchmark focusing on just different possible sorting of enum fields (this is with 3948 fields in the enum, shortest field length is 3 and longest is 43):
This would ultimately be a trade-off between compile time and runtime performance. I haven't tested to see how much of an impact on the compile time the
comptime
sorting of the fields would incur. We might end up hitting #4055, in which case this optimization might need to wait a bit.Note: Sorting would also make it easy to create a fast path that checks that the
str.len
is within the bounds of the longest/shortest enum field.cc @Validark
The text was updated successfully, but these errors were encountered: