GithubHelp home page GithubHelp logo

PEG.buildParser efficiency about pegjs HOT 7 CLOSED

pegjs avatar pegjs commented on May 28, 2024
PEG.buildParser efficiency

from pegjs.

Comments (7)

rymohr avatar rymohr commented on May 28, 2024

Running a quick profile gave me the following biggest offenders:

indentMultilineParts   42.26%   peg.js?body=1 (line 4429)
formatCode             35.47%   peg.js?body=1 (line 4403)
replace                 8.57%   xregexp.js?body=1 (line 336)
map                     6.61%   peg.js?body=1 (line 59)

from pegjs.

rymohr avatar rymohr commented on May 28, 2024

Just forked and noticed indentMultilineParts and formatCode are nowhere to be found. Was this issue already addressed and just hasn't been released yet?

from pegjs.

rymohr avatar rymohr commented on May 28, 2024

If anyone runs into the same issue using v0.6.2 here's the hot fix until the next version gets released (which appears to have a new emitter):

--- peg.js
+++ peg.js
@@ -4441,7 +4441,9 @@ PEG.compiler.emitter = function(ast) {
     var args = Array.prototype.slice.call(arguments);
     var vars = args[args.length - 1] instanceof Object ? args.pop() : {};

-    return indentMultilineParts(interpolateVariablesInParts(args)).join("\n");
+    // We want fast parsers, not pretty ones!
+    // return indentMultilineParts(interpolateVariablesInParts(args)).join("\n");
+    return interpolateVariablesInParts(args).join("\n");
   };

   /* Unique ID generator. */

from pegjs.

dmajda avatar dmajda commented on May 28, 2024

As you correctly discovered, the code emitter is the slow part here. Both the old and new emiter have performance problems with your example.

As a workaround, you may try to split the big choice into many smaller ones. For example, instead of

start = a1 / a2 / a3 / a4 / a5 / a6 / a7 / a8 / a9

you can use

start = a13 / a46 / a79
a13 = a1 / a2 / a3
a46 = a4 / a5 / a6
a79 = a7 / a8 / a9

This causes less passes through the templating engine in the emitter.

I'll keep this issue open because the emiter performance clearly is a problem, but it isn't a big priority for me (performance of the generated parser is).

from pegjs.

rymohr avatar rymohr commented on May 28, 2024

Thanks I'll keep in that mind. Right now I'm still using the old version
with the patch above and it's working fine for my needs.

from pegjs.

ewindso avatar ewindso commented on May 28, 2024

Hi there -- Yep I'm experiencing the same thing. I thought of saving the parser as a string, however it comes out to > 3MB! Any more solutions, by chance? I'm using it with Node.js, and PEG version 0.7.0.

from pegjs.

dmajda avatar dmajda commented on May 28, 2024

The original Gist is gone (so this is not reproducible anymore), the code generator was rewritten meanwhile, and there are no users complaining about this bug since 2012. Closing.

from pegjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.