Skip to content
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

module: cache stat() results more aggressively #4575

Closed
wants to merge 4 commits into from

Commits on Jan 7, 2016

  1. fs: change statSync to accessSync in realpathSync

    fs.statSync() creates and returns a heavy-weight fs.Stat object whereas
    fs.accessSync() simply returns nothing.  The return value is ignored,
    the call is for its side effect of throwing an ELOOP error in case of
    cyclic symbolic links.
    bnoordhuis committed Jan 7, 2016
    Configuration menu
    Copy the full SHA
    66265f1 View commit details
    Browse the repository at this point in the history
  2. module: cache stat() results more aggressively

    Reduce the number of stat() system calls that require() makes by caching
    the results more aggressively.
    
    To avoid unbounded growth without implementing a LRU cache, scope the
    cache to the lifetime of the first call to require().  Recursive calls
    (i.e. require() calls in the included code) transparently profit from
    the cache.
    
    The benchmarked application is the loopback-sample-app[0] and it sees
    the number of stat calls at start-up go down by 40%, from 4736 to 2810.
    
    [0] https://github.com/strongloop/loopback-sample-app
    bnoordhuis committed Jan 7, 2016
    Configuration menu
    Copy the full SHA
    d67de9b View commit details
    Browse the repository at this point in the history
  3. module: avoid ArgumentsAdaptorTrampoline frame

    Avoid an unneeded ArgumentsAdaptorTrampoline stack frame by passing the
    the right number of arguments to Module._load() in Module.require().
    Shortens the following stack trace with one frame:
    
        LazyCompile:~Module.load module.js:345
        LazyCompile:Module._load module.js:282
        Builtin:ArgumentsAdaptorTrampoline
        LazyCompile:*Module.require module.js:361
        LazyCompile:*require internal/module.js:11
    bnoordhuis committed Jan 7, 2016
    Configuration menu
    Copy the full SHA
    359281b View commit details
    Browse the repository at this point in the history

Commits on Jan 8, 2016

  1. 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
    bnoordhuis committed Jan 8, 2016
    Configuration menu
    Copy the full SHA
    2e672b6 View commit details
    Browse the repository at this point in the history