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

Truffle new pack parser #3519

Merged
merged 12 commits into from
Dec 10, 2015
Merged

Truffle new pack parser #3519

merged 12 commits into from
Dec 10, 2015

Conversation

chrisseaton
Copy link
Contributor

This is Array#pack reimplemented using Antlr instead of a hand-written lexer and parser. It's good software engineering, but it's also practice for developing a new new parser for Ruby in Antlr.

@nirvdrum @pitr-ch @eregon please review - @headius and @enebo for info as you asked about this at RubyConf.

@chrisseaton chrisseaton added this to the truffe milestone Dec 6, 2015
@chrisseaton chrisseaton self-assigned this Dec 6, 2015
@eregon
Copy link
Member

eregon commented Dec 8, 2015

Looks good. Do we have any perf numbers compared to the manual parser?

@chrisseaton
Copy link
Contributor Author

For the parsing itself? No - I'll do that. That's not what it's designed for of course.

@eregon
Copy link
Member

eregon commented Dec 8, 2015

Yes, I recall doing one lexer with jflex for Date#strftime(format) parsing and numbers were interesting.

@chrisseaton
Copy link
Contributor Author

It turns out it's quite a bit slower.

final PackParser parser = new PackParser(this);

while (true) {
    final long start = System.nanoTime();

    for (int n = 0; n < 1_000_000; n++) {
        parser.parse("LI<BaL>Q<nnD@", false);
    }

    System.err.println((System.nanoTime() - start) / 1e9);
}
7.178332954
6.426043492
4.051578236
4.001246475
3.96417664
4.009482471
4.048091502
4.03034866
final PackCompiler compiler = new PackCompiler(this, null);

while (true) {
    final long start = System.nanoTime();

    for (int n = 0; n < 1_000_000; n++) {
        compiler.compile("LI<BaL>Q<nnD@");
    }

    System.err.println((System.nanoTime() - start) / 1e9);
}
31.487802185
30.452111491
30.422754027
30.572044818
30.423045225
30.470363756

I'd still rather have this nice code in there for now though, and it's not putting me off trying a Ruby parser in Antlr4.

chrisseaton added a commit that referenced this pull request Dec 10, 2015
@chrisseaton chrisseaton merged commit ac552f5 into master Dec 10, 2015
@chrisseaton chrisseaton deleted the truffle-new-pack-parser branch December 10, 2015 19:19
@chrisseaton
Copy link
Contributor Author

The Antlr dependency is 374 KB.

@chrisseaton chrisseaton modified the milestones: truffe, truffle-dev Dec 19, 2015
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
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

Successfully merging this pull request may close these issues.

None yet

3 participants