Skip to content

Various assorted performance improvements#1486

Open
gsmet wants to merge 5 commits intosmallrye:mainfrom
gsmet:configmappingcontext
Open

Various assorted performance improvements#1486
gsmet wants to merge 5 commits intosmallrye:mainfrom
gsmet:configmappingcontext

Conversation

@gsmet
Copy link
Contributor

@gsmet gsmet commented Mar 10, 2026

See individual commit comments for the details.

Note that I think we really need to review all the places where PropertyName is used in a HashSet or HashMap and either use a more sophisticated approach for matching or use List instead as, in the end, it's better to use a List than a HashSet/HashMap.

I think this work is a good first step and ^ requires more SmallRye Config expertise.

gsmet added 5 commits March 10, 2026 22:18
Instead of iterating through all property names, the createRequired()
method now uses the index to only examine properties with the relevant
prefix.
PropertyName hashCode() is not designed for being used in an
HashSet/HashMap so we should avoid it at all costs.
It is both inefficient when populating the HashSet/HashMap and when
getting the elements from it.

Also fixes substring calculation for .** patterns (it was dropping the
dot, which we actually want to keep).
Identifying prefixing that we ignore from the get go allows to filter
things a lot more efficiently and avoid populating filters with elements
that we will in any case not consider because of the ignored prefixes.

This reduces the population cost and also the interrogation cost.
Check if secretKeys is empty before calling contains() to avoid
unnecessary allocations and hash lookups when there are no secret
keys configured.

Note that again we shouldn't use a HashSet to store PropertyNames for
secret keys and that's something that IMHO requires a more global fix.

Also don't enter complex logic to match [ if there's no [ in the
property name.
Comment on lines +152 to +183
private void buildPropertyPrefixIndex() {
for (String propertyName : config.getPropertyNames()) {
// Index by all prefixes: "foo.bar.baz" -> index under "foo", "foo.bar", "foo.bar.baz"
// Also handle indexed properties: "foo.bar[0]" -> index under "foo", "foo.bar"
int dotIndex = 0;
int lastDotIndex = -1;
while (dotIndex < propertyName.length()) {
dotIndex = propertyName.indexOf('.', dotIndex);
if (dotIndex == -1) {
// No more dots - check if there's a bracket in the last segment
int searchStart = lastDotIndex + 1;
int bracketIndex = propertyName.indexOf('[', searchStart);
if (bracketIndex != -1) {
// Index under the part before the bracket: "foo.bar[0]" -> index under "foo.bar"
String prefixBeforeBracket = propertyName.substring(0, bracketIndex);
propertyPrefixIndex.computeIfAbsent(prefixBeforeBracket, k -> new HashSet<>())
.add(propertyName);
} else {
// No bracket in last segment - index under the full property name
propertyPrefixIndex.computeIfAbsent(propertyName, k -> new HashSet<>())
.add(propertyName);
}
break;
}
String prefix = propertyName.substring(0, dotIndex);
propertyPrefixIndex.computeIfAbsent(prefix, k -> new HashSet<>())
.add(propertyName);
lastDotIndex = dotIndex;
dotIndex++;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, I'm not entirely sure this is completely correct from a functional point of view. Tests are passing but it needs better scrutiny from someone from the project :).

Comment on lines -201 to +250
ignoredPrefixes.add(ignoredPath.substring(0, ignoredPath.length() - 3));
ignoredPrefixes.add(ignoredPath.substring(0, ignoredPath.length() - 2));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is actually a bugfix. We need to keep the dot at the end of the prefix.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant