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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java String Performance 馃悓 #80

Open
pascaldekloe opened this issue Dec 19, 2023 · 0 comments
Open

Java String Performance 馃悓 #80

pascaldekloe opened this issue Dec 19, 2023 · 0 comments

Comments

@pascaldekloe
Copy link
Owner

Java has no performant API to access String content. Colfer version 1 uses charAt which causes range checks on every UTF-16 character. All other access methods are even slower due to memory allocation.

    for (java.lang.reflect.Field f : String.class.getDeclaredFields())
        System.err.printf("%s %s %s\n", java.lang.reflect.Modifier.toString(f.getModifiers()), f.getType().getTypeName(), f.getName());

The String class in LTS version 8 has a private final char[] value payload. LTS version 11, 17, 21, and the OpenJDK moved to the following layout.

private final byte[] value
private final byte coder
static final boolean COMPACT_STRINGS
static final byte LATIN1
static final byte UTF16

The coder can be either LATIN1 for ISO 8859-1, or UTF-16 for big-endian bytes. COMPACT_STRINGS must be read as well because LATIN1 is 0 and UTF-16 is 1 instead of the other way around. 馃う

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