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

Performance issue in StringUtil #29

Open
jkronegg opened this issue Mar 22, 2023 · 0 comments
Open

Performance issue in StringUtil #29

jkronegg opened this issue Mar 22, 2023 · 0 comments

Comments

@jkronegg
Copy link

Observed behavior

In my project, I generate Markdown tables with this library. Using the IntelliJ profiler, I observed that the library takes about 9% of the total time to generate the tables. About 30% of this 9% is consumed in StringUtils.fillUpAligned.

This is most probably because of multiple String concatenation:

public static String fillUpLeftAligned(String value, String fill, int length) {
    if (value.length() >= length) {
        return value;
    }
    while (value.length() < length) {
        value += fill;
    }
    return value;
}

public static String fillUpRightAligned(String value, String fill, int length) {
    if (value.length() >= length) {
        return value;
    }
    while (value.length() < length) {
        value = fill + value;
    }
    return value;
}

For example, using the debugger, I've seen calls with value="", fill="-", length=39 (that is: the String underlying character array is redefined 39 times during the alignment).

Desired behavior

The StringUtil alignment methods should be improved to use better performing String composition (e.g. StringBuilder).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant