Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-allocate error vector in TRY (facebookincubator#9986)
Summary: Pull Request resolved: facebookincubator#9986 TRY(CAST(...)) is up to 4x slower than TRY_CAST when many rows fail. The profile reveals that significant percentage of cpu time goes to EvalCtx::ensureErrorsVectorSize. For every row that fails, we call EvalCtx::ensureErrorsVectorSize to resize the error vector to accommodate that row. When many rows fail we end up resizing a lot: resize(1), resize(2), resize (3),....resize(n). Fix this by pre-allocating error vector in TryExpr. An earlier attempt at fixing this facebookincubator#9911 caused 2x memory regression in one of the streaming pipelines. The change was reverted: facebookincubator#9971 The regression was due to TRY starting to allocate 'nulls' buffer in results unconditionally. Even if there were no errors, TRY would still allocate 'nulls' buffer. When result is a boolean vector, allocating unnecessary 'nulls' buffer increases memory usage for 'result' by 2x. This fix makes sure not to do that and adds a test. Also, this change creates ErrorVector with only nulls buffer allocated. The 'values' buffer that requires ~20 bytes per row is allocated only if an error occurs. Before: ``` ============================================================================ [...]hmarks/ExpressionBenchmarkBuilder.cpp relative time/iter iters/s ============================================================================ cast##try_cast_invalid_empty_input 2.27ms 440.97 cast##tryexpr_cast_invalid_empty_input 8.96ms 111.56 cast##try_cast_invalid_nan 5.49ms 182.26 cast##tryexpr_cast_invalid_nan 12.96ms 77.17 ``` After: ``` cast##try_cast_invalid_empty_input 2.22ms 451.34 cast##tryexpr_cast_invalid_empty_input 4.52ms 221.06 cast##try_cast_invalid_nan 5.79ms 172.69 cast##tryexpr_cast_invalid_nan 8.16ms 122.48 ``` Reviewed By: xiaoxmeng, bikramSingh91 Differential Revision: D57968341 fbshipit-source-id: d9f44aeda56596d9efb035ff9fada5eae22bea1d
- Loading branch information