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

Tunes the initial size of various reusable ArrayLists to reduce required growth when processing real-world data. #1048

Open
wants to merge 1 commit into
base: ion-11-encoding-optimize-initial-expression-array-size-session-pools-merge-presencebitmap-pool-no-lambdas-no-arraylistitr
Choose a base branch
from
Open
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 @@ -1221,7 +1221,7 @@ private class EncodingDirectiveReader {

boolean isSymbolTableAppend = false;
boolean isMacroTableAppend = false;
List<String> newSymbols = new ArrayList<>(8);
List<String> newSymbols = new ArrayList<>(128);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
List<String> newSymbols = new ArrayList<>(128);
List<String> newSymbols = new ArrayList<>(128); // ion-java #1048

Map<MacroRef, Macro> newMacros = new LinkedHashMap<>();
MacroCompiler macroCompiler = new MacroCompiler(this::resolveMacro, readerAdapter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class EExpressionArgsReader {
private final ReaderAdapter reader;

// Reusable sink for expressions.
protected final List<Expression.EExpressionBodyExpression> expressions = new ArrayList<>(16);
protected final List<Expression.EExpressionBodyExpression> expressions = new ArrayList<>(128);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
protected final List<Expression.EExpressionBodyExpression> expressions = new ArrayList<>(128);
protected final List<Expression.EExpressionBodyExpression> expressions = new ArrayList<>(128); // ion-java #1048


protected final PooledExpressionFactory expressionPool = new PooledExpressionFactory();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/amazon/ion/impl/macro/MacroCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ internal class MacroCompiler(
var macroName: String? = null
private set // Only mutable internally

private val signature: MutableList<Macro.Parameter> = mutableListOf()
private val expressions: MutableList<TemplateBodyExpression> = mutableListOf()
private val signature: MutableList<Macro.Parameter> = ArrayList(16)
private val expressions: MutableList<TemplateBodyExpression> = ArrayList(64)
Comment on lines +24 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private val signature: MutableList<Macro.Parameter> = ArrayList(16)
private val expressions: MutableList<TemplateBodyExpression> = ArrayList(64)
private val signature: MutableList<Macro.Parameter> = ArrayList(16) // ion-java #1048
private val expressions: MutableList<TemplateBodyExpression> = ArrayList(64) // ion-java #1048


/**
* Compiles a template macro definition from the reader. Caller is responsible for positioning the reader at—but not
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amazon/ion/impl/macro/MacroEvaluator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MacroEvaluator {
/** Pool of [Expression] to minimize allocation and garbage collection. */
val expressionPool: PooledExpressionFactory = PooledExpressionFactory()
/** Pool of [ExpansionInfo] to minimize allocation and garbage collection. */
private val expanderPool: ArrayList<ExpansionInfo> = ArrayList(32)
private val expanderPool: ArrayList<ExpansionInfo> = ArrayList(64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private val expanderPool: ArrayList<ExpansionInfo> = ArrayList(64)
private val expanderPool: ArrayList<ExpansionInfo> = ArrayList(64) // ion-java #1048

private var expanderPoolIndex = 0

/**
Expand Down