Performance: Reading data with Readable streams
MEDIUM IMPACT
This concept affects how fast data is processed and delivered to the application, impacting input responsiveness and memory usage.
const fs = require('fs'); const stream = fs.createReadStream('largefile.txt', { encoding: 'utf8' }); stream.on('data', chunk => console.log(chunk));
const fs = require('fs'); const data = fs.readFileSync('largefile.txt', 'utf8'); console.log(data);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous readFileSync | N/A | N/A | Blocks event loop, delays UI updates | [X] Bad |
| Asynchronous Readable stream | N/A | N/A | Non-blocking, smooth UI responsiveness | [OK] Good |