venkata91 opened a new issue, #19294: URL: https://github.com/apache/iceberg/issues/19294
`BaseReader.next()` calls `System.nanoTime()` at the start and again in `finally` to add to `scanDurationNanos`. On the batch path that's twice per batch, which is fine. On the row path `next()` runs once per row, so we pay two clock reads for every row. @gerashegalov measured this while reviewing #19022: about 37 ns/row, which is +58% on a narrow `SELECT sum(id)` with vectorization off. Spark itself avoids per-row scan timing for the same reason. `DataSourceScanExec` says "we can't afford to do it for each row". The code is the same in Spark 4.1 and 4.2 on main (`spark/v4.1` and `spark/v4.2` `BaseReader.next()`), and the 3.5 and 4.0 backports (#19022, #18775) copy it. So I think it's best fixed on main for all versions at once. scanDuration hasn't shipped yet (it's not in 1.12.0), so if we fix it before 1.13 nobody ever sees the slower row path. A couple of options, I'm not set on either: 1. Only time the row path at task boundaries. Keep per-call timing in `BatchDataReader` (one call per batch), and on the row path time `open(task)` plus a pair of clock reads around each task's rows instead of each row. That's one pair per file instead of one per row. The catch is that the per-task window also counts time Spark spends between `next()` calls, so the row path would report wall time for the whole task rather than time inside the reader. 2. Sample on the row path. Time every Nth `next()` call and scale up, which keeps the meaning of the metric and cuts the cost by N. It's an estimate though, and it's less accurate on small splits. If neither fits, making the row path skip scanDuration entirely (report 0 or leave it out) is the simplest fallback, but I'd rather keep the metric on both paths. -- 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]
