Repository navigation
Conversation
alexeagle
left a comment
There was a problem hiding this comment.
cool! need any help to get the CI green?
| const DEBUG = false; | ||
| // worker_threads is only avilable on version > 10.5.0 | ||
| const [major, minor] = process.version.replace('v', '').split('.'); | ||
| const WORKER_THREADS_AVILABLE = major > 10 || major == 10 && minor > 5 |
There was a problem hiding this comment.
nit: why not just try/catch on the require call?
There was a problem hiding this comment.
Total guess here, but I would assume that doing arithmetic is faster than recovering from an exception.
However, in hindsight, it's probably the smallest amount of performance difference here.
| console.warn( | ||
| `WARNING: worker_threads not are not avilable on your version of Nodejs: ${process.version} | ||
| Running Terser in serial mode | ||
| Upgrade your Nodejs version to 10.5.0 minimum for worker_threads to be avilable`) |
There was a problem hiding this comment.
we should be more specific here, to update the /WORKSPACE file, otherwise users will update the nodejs on their machine and it still won't work
| * @param {boolean} debug | ||
| */ | ||
| async function runTerserParallel(files, debug) { | ||
| // TODO: do some concurrency limiting here |
There was a problem hiding this comment.
do we have to finish the TODO before we merge/release this?
There was a problem hiding this comment.
We should. context switching will destroy performance gains.
os.cpus().length - 1 is typically a good cap.
There was a problem hiding this comment.
I think a worker pool would also make sense here. There's no need to tear down and bring up new threads and re-initialize terser for each file.
| } else { | ||
| console.warn( | ||
| `WARNING: worker_threads not are not avilable on your version of Nodejs: ${process.version} | ||
| Running Terser in serial mode |
There was a problem hiding this comment.
"serial mode" is a bit obtuse for a novice user, how about just "optimizing one file at a time"
| args.add("--beautify") | ||
|
|
||
| # we need this arg to enable worker_threads | ||
| args.add("--node_options=--experimental-worker") |
There was a problem hiding this comment.
If on Node 12+ this shouldn't be added
There was a problem hiding this comment.
Fair, not sure how to get the nodejs version in in skylark though.
@alexeagle You mentioned there's a way to do it the other day?
There was a problem hiding this comment.
Once we have toolchains in it would actually be possible to add the node version to the toolchain and then one could get it in starlark. Not sure though how it would be possible currently though.
There was a problem hiding this comment.
If problematic, node 12 currently won't error with the option present. So this could be addressed moving forward.
Toxicable
left a comment
There was a problem hiding this comment.
Thanks for the review.
I do have a few points I'm not 100% on, I've commented on them below.
If we could resolve those then I think we're good to go here.
| "shelljs": "0.8.3", | ||
| "source-map-explorer": "^1.7.0", | ||
| "terser": "^3.16.1", | ||
| "p-limit": "^2.2.0", |
There was a problem hiding this comment.
This dosen't actually work, how do we add internal npm modules?
| return {inputFile, outputFile, sourceMapFile: outputFile + '.map'}; | ||
| }) | ||
|
|
||
| // TODO: allow config to force serial workers here |
There was a problem hiding this comment.
@Globegitter Suggested this one.
It would be a good addition but probably not apart of this first cut.
| * @param {boolean} debug | ||
| */ | ||
| async function runTerserParallel(files, debug) { | ||
| // TODO: make this configurable |
There was a problem hiding this comment.
Same here, would be a good candidate for config, but we'll worry about it later I think
| if (result.error) { | ||
| // TODO: figure out error reporting here | ||
| // scroll up a little from this: https://github.com/terser-js/terser#minify-options | ||
| throw result.error; |
There was a problem hiding this comment.
Im not certain of the format of this error object, we need to do some trial and error I think to figure out what kind of errors we get from Terser.
However, I'm not familiar enough with Terser to know how to cause an error :P
|
|
||
| if (DEBUG) console.error(`Running node ${args.join(' ')}`); | ||
| const terserOptions = buildTerserConfig(sourceMapFile, debug) | ||
| const inputCode = (await fs.promises.readFile(inputFile)).toString(); |
There was a problem hiding this comment.
Are character encoding and BOM presence relevant here? This is currently assuming UTF-8.
There was a problem hiding this comment.
I really don't know. We could add a trim() call which would remove the BOM if it is actually encoded as that.
I don't know the impact of stripping the BOM and re-writing it as plain UTF8 once we're done
|
replaced with #1172 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information