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
Removed upb_Decoder's stateful, bespoke logic for field lookup.
upb_Decoder used to have its own logic for finding a MiniTable field by number. Instead of using the standard `upb_MiniTable_FindFieldByNumber()` function, it used a custom linear search that cached the most recently seen field index. The theory behind this design was that field numbers are usually serialized in increasing order, so by linear searching from the last seen index, we would have a small expected number of elements to inspect before finding the matching one.
In practice, it appears that we can use the generic searching logic with no loss in performance -- in fact, performance increases by as much as 6% (see attached benchmark results).
Removing the stateful search has several benefits:
1. This simplifies the decoder since we no longer have to preserve this extra state (`last_field_index`). Note that it was not even possible to put this variable into `upb_Decoder` because it is preserved per parsed message, so we previously needed a *stack* of `last_field_index` values. This CL lets us get rid of that completely.
2. This makes parsing performance less sensitive to whether field numbers are serialized in order.
3. This simplification will help as we refine the dispatch logic that switches between the standard and fasttable decoders.
PiperOrigin-RevId: 758304268
0 commit comments