Skip to content

Commit 5e92745

Browse files
committed
Integrate time-require when debug is enabled.
I want to start focusing on getting our require times down, both in the main thread and forked tests. This adds `time-require` support directly to the CLI to assist in that. This is especially important for forked test processes, where I currently have to manually add a line of code each time I want to test an optimization. I don't think this should be a publicly documented move. I think we want the freedom to remove this once we are happy with performance. I have placed comments above all `time-require` references, indicating it is for internal use only. Users have been given fair warning against relying on its inclusion long term. Usage: ```sh $ DEBUG=ava ./cli.js test/fixture/es2015.js --sorted ``` `--sorted` is optional. It sorts the requires from most expensive to least. The default is sequential sorting. The output will display multiple `time-require` reports. One for each forked process, and the last one for the main thread.
1 parent fa70351 commit 5e92745

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

cli.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/usr/bin/env node
22
'use strict';
3+
4+
var debug = require('debug')('ava');
5+
6+
if (debug.enabled) {
7+
require('time-require');
8+
}
9+
310
var fs = require('fs');
411
var path = require('path');
512
var figures = require('figures');
@@ -109,6 +116,12 @@ function run(file) {
109116
args.push('--serial');
110117
}
111118

119+
// Forward the `time-require` `--sorted` flag.
120+
// Intended for internal optimization tests only.
121+
if (cli.flags.sorted) {
122+
args.push('--sorted');
123+
}
124+
112125
return fork(args)
113126
.on('stats', stats)
114127
.on('test', test)

lib/babel.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
'use strict';
22

3+
var debug = require('debug')('ava');
4+
5+
if (debug.enabled) {
6+
require('time-require');
7+
}
8+
39
// Bind globals first, before anything has a chance to interfere.
410
var globals = require('./globals');
511

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"set-immediate-shim": "^1.0.1",
110110
"source-map-support": "^0.3.3",
111111
"squeak": "^1.2.0",
112+
"time-require": "^0.1.2",
112113
"update-notifier": "^0.5.0"
113114
},
114115
"devDependencies": {

0 commit comments

Comments
 (0)