Skip to content

Refactor toStringEscaped method for improved efficiency and clarity#16323

Open
rajat315315 wants to merge 2 commits into
apache:mainfrom
rajat315315:toStringEscaped_opt
Open

Refactor toStringEscaped method for improved efficiency and clarity#16323
rajat315315 wants to merge 2 commits into
apache:mainfrom
rajat315315:toStringEscaped_opt

Conversation

@rajat315315

Copy link
Copy Markdown

Description

@neoremind

neoremind commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR! A bit thoughts purely on performance.

Searching code, the only caller passes wildcardChars = {'*', '?'}, just 2 chars. The current impl's inner loop is as tight as iterating two chars, which I think JIT can unroll. The additional BitSet(1 << 16) allocates as large as 8KB array for each invocation with usually short query terms input in realworld, and the array is super sparse, we may need to weight the cost of such relatively large memory allocation vs. tight loop over small num of chars working on top of short inputs with a micro benchmark. I guess the the BitSet approach might not be as good as predicted.

Also if this method is not in critical call path, it would be better to just remove the TODO comment as the current impl is clean and simple.

@dweiss

dweiss commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

I agree with @neoremind 's assessment. It looks like an improvement but the extra memory allocation may kill any gains. It'd require some careful benchmarks (not just microbenchmarks but full-stack benchmarks) to see the impact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants