-
Notifications
You must be signed in to change notification settings - Fork 418
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
Optimize silent fails: remove checks that always false #399
Conversation
34d0485
to
156a6af
Compare
156a6af
to
0313ac7
Compare
f17269c
to
b2fd6a8
Compare
Last measurement show, that speed impact equals 1-4% ( $ ./impact master optimize-silent-fails
Measuring commit master... OK
Measuring commit optimize-silent-fails... OK
Speed impact
------------
Before: 544.60 kB/s
After: 556.25 kB/s
Difference: 2.13%
Size impact
-----------
Before: 669581 b
After: 641730 b
Difference: -4.16%
(Measured by /tools/impact with Node.js v4.5.0 on MINGW64_NT-6.1 2.3.0(0.291/5/3) x86_64.) |
b2fd6a8
to
524e25c
Compare
6178798
to
cadee7f
Compare
test/unit/compiler/passes/helpers.js
Outdated
options.allowedStartRules = ast.rules.length > 0 | ||
? [ast.rules[0].name] | ||
: []; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for this? ast.rules.length
is always 1 or more, and the default value for options.allowedStartRules
is [ast.rules[0].name]
, so there shouldn't be a need for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ast.rules.length
is always 1 or more
parse
contract not guarantee it. Grammar without any rules still valid and can be occured in tests. The same reason for which all this if
block in general exists -- tests are the special code demanding the special relation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean the parse contract doesn't guarantee it? The parser currently generated from the grammar will throw an error when a grammar without any rules is passed to it, so it is guaranteed that there will always be one rule from the PEG.js parser.
As I could not find a test case that ensured empty grammars are not accepted by the parser, I added one on my development-overhaul branch.
As for the compiler option allowedStartRules
, since there will always be at least 1 rule, you can always expect it to be set as the compiler option default for allowedStartRules
, so there's no need to set this, even in the test's, unless you are intentionally passing a rule name that doesn't exist to ensure the compiler throws an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser currently generated from the grammar will throw an error when a grammar without any rules is passed to it
This is implementation detail. There are no reasonable reasons to do it. And if it changes in the future, tests which do not depend on it shall not fall. To test in the assumption as the code works means that you have no tests.
so there's no need to set this, even in the test's,
As it is possible to see few lines above, the options
can be not supplied to the test and then it is meant empty. Thus, malformed data which to it shall not be supplied are obviously supplied to pass. Whether means it that the test in principle is totally wrong because it tries to expect correct behavior from a code, supply it certainly malformed data?
From this point of view this code only adds reasonable defaults to a test code, without forcing the developer of tests to supply their every time. Such simplification of operation is also required from the utility method, you do not agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I do plan to add module support (#523) and annotations, it is likely in the future that there will be grammar files without rules, and you are correct that having this in the helper could actually be a plus for any developers making tests, so I accept this change, but can you extract this into a separate PR as this is a separate issue from this PR.
While you're at it, could you also in this new PR remove the related if ( options.allowedStartRules )
in lib/compiler/passes/report-undefined-rules.js#L22
If you don't want to make the new PR, just tell me and remove this code snippet from this PR, then I'll do the new PR at a later date.
cadee7f
to
375cc1b
Compare
375cc1b
to
3bfcdc6
Compare
OK, now changes in the test helper method done in the #541 and this rebased on top of that. I also rewrote some parts (bugfix for not handling |
// Determines if rule always used in disabled report failure context, | ||
// that means, that any failures, reported within it, are never will be | ||
// visible, so the no need to report it. | ||
function calcReportFailuresForRules(ast, allowedStartRules) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pass is not extracted in the separate file because it strongly influences generation of a bytecode, and therefore shall be tested together with generation of a bytecode. Actually, it is just a detail of implementation of the bytecode generator
18, 0, 2, 2, 22, 0, 23, 1 // <expression> | ||
])); | ||
}); | ||
|
||
it("defines correct constants", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added because I noticed, that for group
node I forgot to update my PR for it, but tests did not tell me about that.
cc04fda
to
bf82874
Compare
1 similar comment
ready to merge? |
Wait some time. I prepare the next PR with attempt to partially fix #194. It seems, it clashes with these changes |
…nts for it (local to rule).
…nts for it (non local to rule).
bf82874
to
ee47279
Compare
Now it is ready to merge |
The first сommit removed unnecessary checks with
peg$silentFails
if earlier in the parse function for the rule this variable was incremented. The second commit extends optimization for boundaries of rules: if rule always used in context of suppressed failure generation (there three of such context -- rules undernamed
,simple_and
andsimple_not
AST nodes) checks aren't generated.The size of the generated parsers slightly decreased, and speed, most likely, didn't change though it would be worth expecting small improving. Measurements yield contradictory results, here the most noticeable of them with deviations in both sides (from 7 carried-out tests, in remaining distinction sticks near +/-0.5%, master is 48f5ea4):