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

Handle one simple case of resolving list of += values which #783

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
final class ConfigConcatenation extends AbstractConfigValue implements Unmergeable, Container {

final private List<AbstractConfigValue> pieces;
final List<AbstractConfigValue> pieces;

ConfigConcatenation(ConfigOrigin origin, List<AbstractConfigValue> pieces) {
super(origin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,49 @@ public Object unwrapped() {
@Override
ResolveResult<? extends AbstractConfigValue> resolveSubstitutions(ResolveContext context, ResolveSource source)
throws NotPossibleToResolve {
SimpleConfigList nonRecursiveList = tryResolveSubstitutionsNonRecursiveOptimisticConfigList(stack, origin());
if (nonRecursiveList != null) {
return ResolveResult.make(context, nonRecursiveList);
}
return resolveSubstitutions(this, stack, context, source);
}

/**
* Optimize loading of large configs with many += array builders:
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to add a test case with a problematic example

* 1. Parsing time in one case down from 14sec to 40ms...
* 2. non-recursive - no StackOverflowError
* */
static SimpleConfigList tryResolveSubstitutionsNonRecursiveOptimisticConfigList(
List<AbstractConfigValue> stack,
ConfigOrigin origin
) {
Object prevRef = null;
SimpleConfigList acc = null;
for (int i = stack.size() - 1; i >= 0; i--) {
AbstractConfigValue end = stack.get(i);
if (end instanceof ConfigConcatenation) {
List<AbstractConfigValue> pieces = ((ConfigConcatenation) end).pieces;
if (pieces.size() == 2) {
AbstractConfigValue left = pieces.get(0);
AbstractConfigValue right = pieces.get(1);
if (left instanceof ConfigReference && right instanceof SimpleConfigList) {
if (prevRef == null || prevRef.equals(left)) {
if (acc == null) {
acc = new SimpleConfigList(origin, Collections.emptyList());
}
acc = acc.concatenate(((SimpleConfigList) right));
prevRef = left;
continue;
}
}
}
}
return null;
}

return acc;
}

// static method also used by ConfigDelayedMergeObject
static ResolveResult<? extends AbstractConfigValue> resolveSubstitutions(ReplaceableMergeStack replaceable,
List<AbstractConfigValue> stack,
Expand Down