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 #14

Closed
leouebe95 opened this issue Oct 5, 2017 · 3 comments
Closed

Performance issue #14

leouebe95 opened this issue Oct 5, 2017 · 3 comments

Comments

@leouebe95
Copy link

I converted scripts from another language to NodeJS, and ran into performance issues: The NodeJS version was running 2 to 3 times slower than previous scripts. I tracked it down to the LineByLine.prototype._extractLines method.

Changing the while loop and bufferPosition++ to use directly buffer.indexOf solved the issue. I can provide the code snippet if needed.

Please fix this performance issue in the next release.

@nacholibre
Copy link
Owner

Can you post the fixed code?

@leouebe95
Copy link
Author

leouebe95 commented Oct 6, 2017

here is the version that I use now. I changed only _extractLines.

LineByLine.prototype._extractLines = function(buffer) {
    var line;
    var lines = [];
    var lastNewLine = 0;
    while (true) {
        var nextPos = buffer.indexOf(this.newLineCharacter, lastNewLine)+1;
        if (nextPos > 0) {
            line = buffer.slice(lastNewLine, nextPos);
            lines.push(line);
            lastNewLine = nextPos;
        } else {
            line = buffer.slice(lastNewLine);
            if (line.length) {
                lines.push(line);
            }
            break;
        }
    }

    return lines;
};

@ekeric13
Copy link

Implemented this within a PR:

#15

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

3 participants