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

优化resize,避免fgc #1889

Open
wants to merge 2 commits into
base: 1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public String toString()
*/
private boolean enableFastBuild;

private double minResizeRatio = 1;

/**
* 控制构建过程中每次扩容的最小比例,避免频繁扩容导致FGC
* @param minResizeRatio 扩容比例,取值范围建议(1, 2]
*/
public void setMinResizeRatio(double minResizeRatio) {
this.minResizeRatio = minResizeRatio;
}

/**
* 拓展数组
*
Expand All @@ -91,6 +101,8 @@ public String toString()
*/
private int resize(int newSize)
{
newSize = Math.max(newSize, ((Double)(allocSize * minResizeRatio)).intValue());

int[] base2 = new int[newSize];
int[] check2 = new int[newSize];
if (allocSize > 0)
Expand Down