Commit 7c603280 authored by Ben Noordhuis's avatar Ben Noordhuis Committed by James M Snell
Browse files

module: optimize js and json file i/o

Use internalModuleReadFile() to read the file from disk to avoid the
fs.fstatSync() call that fs.readFileSync() makes.

It does so to know the file size in advance so it doesn't have to
allocate O(n) buffers when reading the file from disk.

internalModuleReadFile() is plenty efficient though, even more so
because we want a string and not a buffer.  This way we also don't
allocate a buffer that immediately gets thrown away again.

This commit reduces the number of fstat() system calls in a benchmark
application[0] from 549 to 29, all made by the application itself.

[0] https://github.com/strongloop/loopback-sample-app

PR-URL: https://github.com/nodejs/node/pull/4575


Reviewed-By: default avatarColin Ihrig <cjihrig@gmail.com>
Reviewed-By: default avatarJames M Snell <jasnell@gmail.com>
parent 038b6365
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment