kamcheungting-db opened a new pull request, #1166:
URL: https://github.com/apache/iceberg-cpp/pull/1166

   ## What this PR does
   
   Makes `Evaluator` (used for residual filters by `FileScanTaskReader`) 
evaluate rows without building a `Literal` per value, and without visiting the 
expression tree per row.
   
   `Evaluator::Make()` now compiles the bound expression once into a small tree 
of evaluation nodes. `Evaluate()` runs those nodes.
   
   ## Why
   
   Per row, the old path:
   
   - visited the bound expression, doing a `dynamic_pointer_cast` (a 
`shared_ptr` copy) for each predicate, and
   - built a `Literal` for every compared value, which copies the type's 
`shared_ptr` singleton (for example `int64()`) and, for strings and bytes, the 
value itself.
   
   With several threads evaluating residuals, every thread updates the same 
atomic reference count of the shared type object, so the cache line bounces 
between cores. In a parallel scan benchmark (Part-5 of the split and parallel 
scans series) a per-row residual made 8 workers *slower* than one thread. A 
`perf` profile put about two-thirds of the samples on the `lock inc`/`lock 
xadd` in `Literal::Long` and `EvalVisitor::GtEq`, and on the virtual call 
through the shared type object in `Literal::operator<=>`.
   
   ## How it works
   
   | Expression | Node |
   |---|---|
   | `true` / `false` | constant |
   | `not`, `and`, `or` | combinators; `and`/`or` still evaluate both sides, 
left first, so a failing row still reports its error |
   | literal or unary predicate on a field reference of a primitive type | 
reads the field's raw `Scalar` and compares it with the bound literal |
   | everything else (set predicates, transforms, unbound expressions, 
aggregates) | the existing literal-based visitor |
   
   The raw comparison matches `Literal` ordering: null and out-of-range 
literals are unordered, `float`/`double` use the total order 
(`std::strong_order`), decimals compare across scales, and strings, binary, 
fixed, and UUIDs compare as unsigned bytes. When a raw value does not have the 
field type's representation, the node falls back to the visitor for that row, 
so results and errors stay the same.
   
   ## Tests
   
   `eval_expr_test` (`evaluator_test.cc`):
   
   - `MatchesLiteralSemantics`: more than 1,000 checks comparing the evaluator 
with `BoundPredicate::Test()` on the literal-based value, across boolean, int, 
date, long, time, timestamp, timestamptz, float, double, decimal, string, 
binary, fixed, and UUID; all literal and unary operations; and nulls, NaNs, 
signed zeros, infinities, prefixes, and high bytes. Changing one comparison 
operator in the new code makes it fail.
   - Compound expressions still report errors from either side; `IN` and 
transform predicates still evaluate correctly.
   
   The existing `expression_test` and `eval_expr_test` suites pass, and the 
full `ctest` suite passes. `pre-commit` is clean.
   
   ## Performance
   
   In the Part-5 benchmark, 8 workers versus a serial scan with an all-pass 
residual on 4 large Parquet files went from 0.80x to 6.72x, and the serial scan 
itself got about 1.9x faster (0.834s to 0.432s). Details are in the Part-5 PR.
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to