mrhhsg opened a new pull request, #70811:
URL: https://github.com/apache/doris/pull/70811

   ### Background
   
   Doris `repeat()` writes each result into a pre-sized string column. Constant 
and row-varying counts share `StringOP::fast_repeat`, which builds the output 
from copies of an expanding prefix.
   
   ### What problem does this PR solve?
   
   Issue Number: None  
   Related PR: [DuckDB #29066](https://github.com/duckdb/duckdb/pull/29066) 
(cache-sized prefix reuse)  
   PR Type: Performance
   
   Problem Summary:
   
   As the prefix grows beyond the CPU cache, constructing a large string 
rereads an increasing portion of the output from memory. Reusing a bounded 
prefix reduces those reads while writing the same result.
   
   ### Details
   
   - **Why it was slow:** The source region grew with the output and eventually 
exceeded the CPU cache.
   - **Optimization:** Double whole copies up to 16 KiB, then reuse the prefix 
for the rest of the output. Inputs above the cap use one copy of the input as 
the block. Single-byte inputs use `memset`.
   - **Results:** A standalone macOS arm64 benchmark of the Doris copy routine 
with Clang `-O3` measured 1.88× speedup for 16 bytes × 4 million, 2.09× for 1 
KiB × 100,000, and 7.57× for 1 byte × 500. A 6-byte result took roughly 6 ns in 
both versions.
   - **Applicability and cost:** Both repeat-count paths use the existing 
output buffer and string-length checks.
   
   ### Testing
   
   - Extended `StringOPTest.testFastRepeat` to cover multiple blocks, a partial 
final block, a pattern above the prefix cap, an embedded NUL, and the 
single-byte fast path.
   - The extracted helper test and 4,187 byte-for-byte comparisons with a 
per-copy reference passed under AddressSanitizer and UndefinedBehaviorSanitizer.
   - The repository formatting check, build hygiene, and `git diff --check` 
passed.
   - The full BE build and integrated BE tests were blocked during dependency 
setup. The benchmark measures the copy routine in isolation.
   
   ### Release note
   
   Improve `repeat()` performance for large outputs and single-byte inputs.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Partially verified. Integrated BE tests and 
SQL-level performance remain unverified.
   
   ### AI Disclosure
   
   - Tool: Codex
   - Generated: Code, tests, and PR description
   - Human review: Not recorded
   


-- 
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