Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Up-to-date JavaScript grammar HOT 2
- Using PEG.js at runtime works, but generated grammer fails to work? HOT 2
- Operator precedence tree compiling extremely slowly HOT 2
- Merging multiple single-character expressions
- Fork of the online editor with inline errors HOT 1
- Ignore me -- wrong project
- [composable, declarative, typescript] react-peg: parser generator based on pegjs
- Bug with context-sensitive grammar HOT 1
- option to generate an es module instead of commonjs module HOT 12
- Cannot use parseFloat inside grammar HOT 4
- literalEscape HOT 1
- Support for runtime context object? HOT 3
- [META] Switch to Peggy HOT 9
- Grammar action errors need to be more informative HOT 4
- Allow access to different rules in code blocks HOT 2
- Using same rule in pattern HOT 2
- Pegjs online can't parser parser.pegjs HOT 2
- Variables in parentheses can't be accessed
- Documentation should describe all features of the grammar specification language (e.g., dollar sign "$", "text()") HOT 3
- Deprecate/archive and recommend peggy.js as official successor project? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pegjs.