Skip to content

Commit

Permalink
fix(perf): update end mark for rules (#1303)
Browse files Browse the repository at this point in the history
With performanceTimer on, we get some nice usertiming measures added. But in #701, some _jerk_ picked an endpoint for rules that I, personally, think can be improved. :)

This moves the end mark of each rule to when the checks have synchronously finished. This change means we don't include the asynchronous bit afterwards, but that async bit is the subject of #1172.

For accurate timing, it makes more sense to keep these measures synchronous. It also makes reading the flame chart more logical.

Screenshots of before and after:
![image](https://user-images.githubusercontent.com/39191/50669976-6f0d9300-0f7d-11e9-8f60-24122a577084.png)



## Reviewer checks

**Required fields, to be filled out by PR reviewer(s)**
- [x] Follows the commit message policy, appropriate for next version
- [x] Has documentation updated, a DU ticket, or requires no documentation change
- [x] Includes new tests, or was unnecessary
- [x] Code is reviewed for security by: @WilcoFiers
  • Loading branch information
paulirish authored and WilcoFiers committed Jan 18, 2019
1 parent a34165c commit a28674e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
16 changes: 1 addition & 15 deletions lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,8 @@ function getRulesToRun(rules, context, options) {
*/
function getDefferedRule(rule, context, options) {
// init performance timer of requested via options
let markStart;
let markEnd;
if (options.performanceTimer) {
markStart = 'mark_rule_start_' + rule.id;
markEnd = 'mark_rule_end_' + rule.id;
// mark start
axe.utils.performanceTimer.mark(markStart);
axe.utils.performanceTimer.mark('mark_rule_start_' + rule.id);
}

return (resolve, reject) => {
Expand All @@ -384,15 +379,6 @@ function getDefferedRule(rule, context, options) {
options,
// resolve callback for rule `run`
ruleResult => {
// if performance timer - mark end & measure
if (options.performanceTimer) {
axe.utils.performanceTimer.mark(markEnd);
axe.utils.performanceTimer.measure(
'rule_' + rule.id,
markStart,
markEnd
);
}
// resolve
resolve(ruleResult);
},
Expand Down
15 changes: 10 additions & 5 deletions lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ Rule.prototype.run = function(context, options, resolve, reject) {

const q = axe.utils.queue();
const ruleResult = new RuleResult(this);
const markStart = 'mark_runchecks_start_' + this.id;
const markEnd = 'mark_runchecks_end_' + this.id;
const markStart = 'mark_rule_start_' + this.id;
const markEnd = 'mark_rule_end_' + this.id;
const markChecksStart = 'mark_runchecks_start_' + this.id;
const markChecksEnd = 'mark_runchecks_end_' + this.id;

let nodes;

Expand All @@ -169,7 +171,7 @@ Rule.prototype.run = function(context, options, resolve, reject) {
'):',
axe.utils.performanceTimer.timeElapsed() + 'ms'
);
axe.utils.performanceTimer.mark(markStart);
axe.utils.performanceTimer.mark(markChecksStart);
}

nodes.forEach(node => {
Expand Down Expand Up @@ -212,12 +214,15 @@ Rule.prototype.run = function(context, options, resolve, reject) {
q.defer(resolve => setTimeout(resolve, 0));

if (options.performanceTimer) {
axe.utils.performanceTimer.mark(markChecksEnd);
axe.utils.performanceTimer.mark(markEnd);
axe.utils.performanceTimer.measure(
'runchecks_' + this.id,
markStart,
markEnd
markChecksStart,
markChecksEnd
);

axe.utils.performanceTimer.measure('rule_' + this.id, markStart, markEnd);
}

q.then(() => resolve(ruleResult)).catch(error => reject(error));
Expand Down

0 comments on commit a28674e

Please sign in to comment.