Skip to content

Java String Performance 🐌  #80

Description

@pascaldekloe

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. 🀦

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions