Skip to content

Conversation

alecgrieser
Copy link
Collaborator

This goes through our codebase and audits our String.format usage. It makes a few changes:

  1. If the String.format call can be replaced with String concatenation, it does so. This mainly means taking cases where strings or numbers are naively placed together (e.g., String.format("%s -> %d", myStr, myInt)) and replacing it with the equivalent concatentation (e.g., myStr + " -> " + myInt). The reason this is done is efficiency: it is more efficient to construct the strings and then concatenate them than to use the Java String formatter most of the time, mainly because the format string parsing is done at runtime with every invocation rather than compiled into some kind of formatting object.
  2. In places where that is more difficult, this ensures that the String.format call has set Locale.ROOT to avoid localization problems. This is what caused Metrics diff test uses locality for report formatting #3645, as the MetricsDiffAnalyzer was formatting numbers with decimals, and then test asserts were firing if the test ran with a different locale, which is a thing we do in our nightly tests. In theory, that's actually sort of appropriate for a tool like this (for example, it would make sense to localize 3.5 to 3,5 if run on a system where that is the convention), but the rest of the product doesn't support it, and it's not like the actual text is localized.

When running on a system with Locale.ROOT, this should be a transparent change.

This fixes #3645.

This goes through our codebase and audits our `String.format` usage. It makes a few changes:

1. If the `String.format` call can be replaced with `String` concatenation, it does so. This mainly means taking cases where strings or numbers are naively placed together (e.g., `String.format("%s -> %d", myStr, myInt)`) and replacing it with the equivalent concatentation (e.g., `myStr + " -> " + myInt`). The reason this is done is efficiency: it is more efficient to construct the strings and then concatenate them than to use the Java `String` formatter most of the time, mainly because the format string parsing is done at runtime with every invocation rather than compiled into some kind of formatting object.
1. In places where that is more difficult, this ensures that the `String.format` call has set `Locale.ROOT` to avoid localization problems. This is what caused FoundationDB#3645, as the `MetricsDiffAnalyzer` was formatting numbers with decimals, and then test asserts were firing if the test ran with a different locale, which is a thing we do in our nightly tests. In theory, that's actually sort of appropriate for a tool like this (for example, it would make sense to localize `3.5` to `3,5` if run on a system where that is the convention), but the rest of the product doesn't support it, and it's not like the actual text is localized.

When running on a system with `Locale.ROOT`, this should be a transparent change.

This fixes FoundationDB#3645.
@alecgrieser alecgrieser added performance Performance issues testing improvement Change that improves our testing labels Oct 3, 2025
@alecgrieser alecgrieser marked this pull request as ready for review October 3, 2025 16:42
Copy link
Contributor

@normen662 normen662 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we want to do one better in Java 21 using JSR 430.

.hasSize(1);
final String predicateDetail = root.getDetails().get(0);
assertThat(predicateDetail)
.as("large where clauses should be converted into a hex representation of their hash")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am going to revert that particular "feature".

@alecgrieser alecgrieser merged commit a3e9c90 into FoundationDB:main Oct 6, 2025
8 checks passed
@alecgrieser alecgrieser deleted the 03645-set-locality branch October 6, 2025 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance issues testing improvement Change that improves our testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics diff test uses locality for report formatting

2 participants