Skip to content

Some performance tweaks#22

Closed
kmh287 wants to merge 2 commits into
zaach:masterfrom
kmh287:kmh287_performance
Closed

Some performance tweaks#22
kmh287 wants to merge 2 commits into
zaach:masterfrom
kmh287:kmh287_performance

Conversation

@kmh287

@kmh287 kmh287 commented Mar 13, 2017

Copy link
Copy Markdown

I'm working on a project where I'm considering using Jison as a parser generator. I've found the following tweaks to the generated parser has given a modest performance improvement. I would like to submit these changes back to you if you want them.

The changes include

  • Changing the lex function to be iterative instead of recursive (remove function call overhead)
  • Caching values from array-indexing in the next function. (On profiling code on my end, a vast majority of the time spent parsing is spent in this function, so every little bit has helped)
  • Adding an early bail out for a newline regex test if a string doesn't contain a newline or carriage return. This change may be too specific to our grammar: we don't really expect any newlines and so bailing out of this test early is the biggest performance boost for us. Let me know and I can remove it.

The modified parser passes all the tests on my side, however you're far familiar with the code than I am so please let me know if you have any feedback on these changes.

Comment thread regexp-lexer.js Outdated

lines = match[0].match(/(?:\r\n?|\n).*/g);
// Bail from match if string doesn't contain newline nor carriage return
if (lines.indexOf('\n') != -1 || lines.indexOf('\r') != -1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: lines isn't initialized here yet. indexOf() should be applied against match[0] instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you're right. Thank you!

GerHobbelt added a commit to GerHobbelt/jison-lex that referenced this pull request Mar 26, 2017
GerHobbelt added a commit to GerHobbelt/jison-lex that referenced this pull request Mar 26, 2017
…thout it for the test grammars ATM; to be revisited later on when zaach#20 is addressed...
@GerHobbelt

Copy link
Copy Markdown
Contributor

related to #17

@kmh287 kmh287 closed this Apr 4, 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.

2 participants