GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: add performance notes for fs.readFile · nodejs/node@7083d99

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • fs.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+23Lines changed: 23 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,28 @@ system requests but rather the internal buffering `fs.readFile` performs.
31563156
the call to `fs.readFile()` with the same file descriptor, would give
31573157
`'World'`, rather than `'Hello World'`.
31583158

3159+
### Performance Considerations
3160+
3161+
The `fs.readFile()` method asynchronously reads the contents of a file into
3162+
memory one chunk at a time, allowing the event loop to turn between each chunk.
3163+
This allows the read operation to have less impact on other activity that may
3164+
be using the underlying libuv thread pool but means that it will take longer
3165+
to read a complete file into memory.
3166+
3167+
The additional read overhead can vary broadly on different systems and depends
3168+
on the type of file being read. If the file type is not a regular file (a pipe
3169+
for instance) and Node.js is unable to determine an actual file size, each read
3170+
operation will load on 64kb of data. For regular files, each read will process
3171+
512kb of data.
3172+
3173+
For applications that require as-fast-as-possible reading of file contents, it
3174+
is better to use `fs.read()` directly and for application code to manage
3175+
reading the full contents of the file itself.
3176+
3177+
The Node.js GitHub issue [#25741][] provides more information and a detailed
3178+
analysis on the performance of `fs.readFile()` for multiple file sizes in
3179+
different Node.js versions.
3180+
31593181
## `fs.readFileSync(path[, options])`
31603182
<!-- YAML
31613183
added: v0.1.8
@@ -6212,6 +6234,7 @@ through `fs.open()` or `fs.writeFile()` or `fsPromises.open()`) will fail with
62126234
A call to `fs.ftruncate()` or `filehandle.truncate()` can be used to reset
62136235
the file contents.
62146236

6237+
[#25741]: https://github.com/nodejs/node/issues/25741
62156238
[Caveats]: #fs_caveats
62166239
[Common System Errors]: errors.md#errors_common_system_errors
62176240
[FS constants]: #fs_fs_constants_1

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.