Skip to content

Unnecessary String construction in MatchesIterator reduces query performance #105

@Emmeral

Description

@Emmeral

In the tryAdvance method of the MatchesIterator class there is the following line

var hasNoText = tree.getText() == null;

This looks to be a simple predicate, but under the hood the Tree#getText() method will to a conversion from a byte array to a String object

    public @Nullable String getText() {
        return charset != null ? new String(source, charset) : null;
    }

This needs some time for Trees with a big underlying text which is a pity as we are not using the constructed string value in the end.

Ideas to solve this

Either add a method hastText() to the Tree class that avoids the unnecessary conversion or reopen #65 to retrieve the raw source bytes (potentially as a read only byte buffer ) in MatchesIterator.

What do you think @ObserverOfTime ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions