Skip to content

IString.asReader has a performance bottleneck #319

@jurgenvinju

Description

@jurgenvinju

We can not use it for serving IString's in a webserver right now, because it has a bottleneck here:

 private CharBuffer nextTillNewlineOrEndOfBuffer() {
                    int start = active.position();
                    int end = start + active.remaining();
                    int cur = start;
                    while (cur < end) {
                        if (active.get(cur) == NEWLINE) {
                            cur++;
                            indentNext = true;
                            break;
                        }
                        cur++;
                    }
                    if (cur != end) {
                        var result = active.duplicate();
                        result.limit(cur);
                        active.position(cur);
                        return result;
                    }
                    else {
                        // end of the buffer
                        var result = active;
                        if (content.hasNext()) {
                            active = content.next();
                        }
                        else {
                            // end of the stream
                            indentNext = false;
                            active = CharBuffer.allocate(0);
                        }
                        return result;
                    }
                }

Current throughput is 0.04 megabytes per second, while we expect at least 250 mb/second on localhost.

This is the CPU profile of a 5 second download of 211 Kb of SVG file:

Image

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions