Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve performance of replacing JDBC {...} escapes #1230

Merged
merged 11 commits into from Jun 29, 2018

style: appendCall correct comment in appendCall

  • Loading branch information...
vlsi committed Jun 29, 2018
commit d8812fac3b98693b76f8b7ea976fc5aa03c111f9
@@ -724,15 +724,17 @@ private static void twoArgumentsFunctionCall(StringBuilder buf, String call, Str
public static void appendCall(StringBuilder sb, String begin, String separator,
String end, List<? extends CharSequence> args) {
int size = begin.length();
// Avoid Iterator instantiations just in case, so plain for, not forach
for (int i = 0; i < args.size(); i++) {
// Typically just-in-time compiler would eliminate Iterator in case foreach is used,
// however the code below uses indexed iteration to keep the conde independent from
// various JIT implementations (== avoid Iterator allocations even for not-so-smart JITs)
int numberOfArguments = args.size();
for (int i = 0; i < numberOfArguments; i++) {
size += args.get(i).length();

This comment has been minimized.

Copy link
@bokken

bokken Jun 29, 2018

Member

is this degree of precision necessary? can we approximate a guess (say 32) for average length of args instead?

This comment has been minimized.

Copy link
@vlsi

vlsi Jun 29, 2018

Author Member

Why approximate when we have exact value?

This comment has been minimized.

Copy link
@bokken

bokken Jun 29, 2018

Member

to avoid the work to calculate the exact value

This comment has been minimized.

Copy link
@vlsi

vlsi Jun 29, 2018

Author Member

The strings would HAVE to be appended, so there will be a walk over the list.
Additional walk is likely to be just free.

Proper size estimation reduces allocation waste.

}
size += separator.length() * (args.size() - 1);
size += separator.length() * (numberOfArguments - 1);
sb.ensureCapacity(sb.length() + size + 1);
sb.append(begin);
// Avoid Iterator instantiations just in case, so plain for, not forach
for (int i = 0; i < args.size(); i++) {
for (int i = 0; i < numberOfArguments; i++) {
if (i > 0) {
sb.append(separator);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.