From 8492e2580ba2b27368ae63ffb2949c3175852ed9 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Thu, 21 Nov 2024 13:32:12 +0100 Subject: [PATCH] LDEV-5156 allow configuring the default capacity for local and arguments scopes https://luceeserver.atlassian.net/browse/LDEV-5156 --- .../java/lucee/runtime/type/scope/ArgumentImpl.java | 8 +++++++- .../main/java/lucee/runtime/type/scope/LocalImpl.java | 9 ++++++++- .../src/main/java/resource/setting/sysprop-envvar.json | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/lucee/runtime/type/scope/ArgumentImpl.java b/core/src/main/java/lucee/runtime/type/scope/ArgumentImpl.java index 647d3ca416..05285bf448 100755 --- a/core/src/main/java/lucee/runtime/type/scope/ArgumentImpl.java +++ b/core/src/main/java/lucee/runtime/type/scope/ArgumentImpl.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; +import lucee.commons.io.SystemUtil; import lucee.commons.lang.CFTypes; import lucee.runtime.PageContext; import lucee.runtime.config.NullSupportHelper; @@ -63,6 +64,11 @@ public final class ArgumentImpl extends ScopeSupport implements Argument, ArrayP private boolean bind; private Set functionArgumentNames; + private static int argumentInitialCapacity; + + static { + argumentInitialCapacity = Caster.toIntValue(SystemUtil.getSystemPropOrEnvVar("lucee.scope.arguments.capacity", "4"), 4); + } // private boolean supportFunctionArguments; /** @@ -70,7 +76,7 @@ public final class ArgumentImpl extends ScopeSupport implements Argument, ArrayP */ public ArgumentImpl() { // super("arguments", SCOPE_ARGUMENTS, StructImpl.TYPE_LINKED, 4); - super("arguments", SCOPE_ARGUMENTS, StructImpl.TYPE_LINKED_NOT_SYNC, 4); + super("arguments", SCOPE_ARGUMENTS, StructImpl.TYPE_LINKED_NOT_SYNC, argumentInitialCapacity); } @Override diff --git a/core/src/main/java/lucee/runtime/type/scope/LocalImpl.java b/core/src/main/java/lucee/runtime/type/scope/LocalImpl.java index 9c2e2978d3..94ebfc0504 100755 --- a/core/src/main/java/lucee/runtime/type/scope/LocalImpl.java +++ b/core/src/main/java/lucee/runtime/type/scope/LocalImpl.java @@ -18,17 +18,24 @@ **/ package lucee.runtime.type.scope; +import lucee.commons.io.SystemUtil; import lucee.runtime.PageContext; +import lucee.runtime.op.Caster; import lucee.runtime.type.Struct; public final class LocalImpl extends ScopeSupport implements Scope, Local { private static final long serialVersionUID = -7155406303949924403L; private boolean bind; + private static int localInitialCapacity; + + static { + localInitialCapacity = Caster.toIntValue(SystemUtil.getSystemPropOrEnvVar("lucee.scope.local.capacity", "4"), 4); + } public LocalImpl() { // super("local", Scope.SCOPE_LOCAL, Struct.TYPE_SYNC, 4); - super("local", Scope.SCOPE_LOCAL, Struct.TYPE_REGULAR, 4); + super("local", Scope.SCOPE_LOCAL, Struct.TYPE_REGULAR, localInitialCapacity); } @Override diff --git a/core/src/main/java/resource/setting/sysprop-envvar.json b/core/src/main/java/resource/setting/sysprop-envvar.json index 0bd4e1e418..26dd60545b 100644 --- a/core/src/main/java/resource/setting/sysprop-envvar.json +++ b/core/src/main/java/resource/setting/sysprop-envvar.json @@ -368,5 +368,15 @@ "sysprop": "lucee.template.charset", "envvar": "LUCEE_TEMPLATE_CHARSET", "desc": "" + }, + { + "sysprop": "lucee.scope.local.capacity", + "envvar": "LUCEE_SCOPE_LOCAL_CAPACITY", + "desc": "Sets the initial capacity (size) for the local scope hashmap" + }, + { + "sysprop": "lucee.scopes.arguments.capacity", + "envvar": "LUCEE_SCOPE_ARGUMENTS_CAPACITY", + "desc": "Sets the initial capacity (size) for the arguments scope hashmap" } ] \ No newline at end of file