Skip to content

Commit 5bbf478

Browse files
Jens-Gclaude
andcommitted
THRIFT-6075: Simplify generated Equal code and reduce its runtime cost
Client: delphi Three changes to generate_equal_container, none of which alter the comparison semantics: 1. Capture operands into locals: the recursion previously passed composed access-path strings down, so expressions like Self.List_field[_i][_k][_k2] (property getter + GetItem + two hash lookups) were re-evaluated at every mention, up to ~8x per loop iteration in deeply nested containers. Operands are now captured into fresh locals once per level (already_local skips the copy where the operand is a loop variable, pair field or snapshot array slot). 2. Compare maps via pair enumeration and TryGetValue: the scalar-key path iterates lhs pairs and fetches the rhs value with a single lookup (was three: ContainsKey + lhs[k] + rhs[k], plus repeated getters). The non-scalar-key consume-scan snapshots rhs keys and values into parallel arrays, removing hash lookups from that path entirely. 3. Exit(False) directly on mismatch: a new exit_on_fail mode lets field-level, list-element and scalar-key-map comparisons leave the generated function immediately instead of threading _eq flags and break statements through every nesting level. The flag-and-fall- through form remains only for the candidate probes inside the set/map consume-scans, where a mismatch means "try the next candidate" rather than "structs differ". Verified by rebuilding the compiler and regenerating ThriftTest, DebugProtoTest and SimpleException in default, com_types and rtti modes: all 358 generated Equal/Equals functions are begin/end-balanced, structs without containers/binaries generate byte-identical code, and the duplicate-element consume-scan regression shape is preserved. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 68d8d68 commit 5bbf478

1 file changed

Lines changed: 216 additions & 113 deletions

File tree

0 commit comments

Comments
 (0)