Skip to content

Commit

Permalink
try two arg pools
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Nov 11, 2024
1 parent 1df6b6c commit 986fbc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
7 changes: 2 additions & 5 deletions core/src/main/java/lucee/runtime/type/UDFImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private Object getCachedWithin(PageContext pc) {
private Object _callCachedWithin(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;

Argument newArgs = pci.getScopeFactory().getArgumentInstance();
Argument newArgs = pci.getScopeFactory().getArgumentInstance(args);
if (args != null) defineArguments(pci, getFunctionArguments(), args, newArgs);
else defineArguments(pci, getFunctionArguments(), values, newArgs);

Expand Down Expand Up @@ -304,10 +304,7 @@ private Object _call(PageContext pc, Collection.Key calledName, Object[] args, S
PageContextImpl pci = (PageContextImpl) pc;
boolean existingNewArgs = newArgs != null;

if (!existingNewArgs){
if (args == null || args.length < 4) newArgs = pci.getScopeFactory().getArgumentInstance();
else newArgs = pci.getScopeFactory().getArgumentInstance(args.length);
}
if (!existingNewArgs) newArgs = pci.getScopeFactory().getArgumentInstance(args);
newArgs.setFunctionArgumentNames(properties.getArgumentsSet());
LocalImpl newLocal = pci.getScopeFactory().getLocalInstance();

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/lucee/runtime/type/scope/ArgumentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ public final class ArgumentImpl extends ScopeSupport implements Argument, ArrayP
private boolean bind;
private Set functionArgumentNames;
// private boolean supportFunctionArguments;

public static final int ARG_DEFAULT_INITIAL_CAPACITY = 4;

/**
* constructor of the class
*/
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, ARG_DEFAULT_INITIAL_CAPACITY);
}

public ArgumentImpl(int size) {
Expand Down
40 changes: 21 additions & 19 deletions core/src/main/java/lucee/runtime/type/scope/ScopeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,26 @@ public final class ScopeFactory {
int argumentCounter = 0;

private final ConcurrentLinkedQueue<Argument> arguments = new ConcurrentLinkedQueue<Argument>();
private final ConcurrentLinkedQueue<Argument> argumentsLarge = new ConcurrentLinkedQueue<Argument>();
private final ConcurrentLinkedQueue<LocalImpl> locals = new ConcurrentLinkedQueue<LocalImpl>();

/**
* @return returns an Argument scope
* most arguments have only 0-3 keys
*/
public Argument getArgumentInstance() {
Argument arg = arguments.poll();
if (arg != null) {
return arg;
public Argument getArgumentInstance(Object[] args) {
if (args == null || args.length < ArgumentImpl.ARG_DEFAULT_INITIAL_CAPACITY){
Argument arg = arguments.poll();
if (arg != null) {
return arg;
}
return new ArgumentImpl();
}
//aprint.o("arguments new! " + arguments.size());
return new ArgumentImpl();
}

/**
* @return returns an Argument scope
*/
public Argument getArgumentInstance(int size) {
Argument arg = arguments.poll();
Argument arg = argumentsLarge.poll();
if (arg != null) {
return arg;
}
//aprint.o("arguments new! " + arguments.size());
return size < 7 ? new ArgumentImpl(8) : new ArgumentImpl(16);
return new ArgumentImpl(ArgumentImpl.ARG_DEFAULT_INITIAL_CAPACITY * 2);
}

/**
Expand All @@ -75,10 +71,16 @@ public LocalImpl getLocalInstance() {
* @param argument recycle an Argument scope for reuse
*/
public void recycle(PageContext pc, Argument argument) {
if (arguments.size() >= MAX_SIZE || argument.isBind()) return;
//if (argument.size() > 0) aprint.o("arg: " + argument.size());
argument.release(pc);
arguments.add(argument);
if (argument.isBind()) return;
if (argument.size() < ArgumentImpl.ARG_DEFAULT_INITIAL_CAPACITY ){
if (arguments.size() >= MAX_SIZE ) return;
argument.release(pc);
arguments.add(argument);
} else {
if (argumentsLarge.size() >= MAX_SIZE ) return;
argument.release(pc);
argumentsLarge.add(argument);
}
}

/**
Expand Down

0 comments on commit 986fbc2

Please sign in to comment.