|
1 | 1 | const WebSocket = require('ws'); |
2 | 2 | const fs = require("fs/promises"); |
| 3 | +const fsNormal = require("fs"); |
3 | 4 | const path = require("path"); |
4 | 5 | const os = require('os'); |
5 | 6 | const { exec } = require('child_process'); |
6 | 7 | const chokidar = require('chokidar'); |
7 | | -const anymatch = require('anymatch'); |
8 | 8 | const ignore = require('ignore'); |
9 | 9 | const crypto = require('crypto'); |
10 | 10 |
|
@@ -255,10 +255,17 @@ function _stat(ws, metadata) { |
255 | 255 |
|
256 | 256 | function _readBinaryFile(ws, metadata) { |
257 | 257 | const fullPath = metadata.data.path; |
258 | | - fs.readFile(fullPath) |
259 | | - .then(data => { |
260 | | - _sendResponse(ws, metadata, {}, toArrayBuffer(data)); |
261 | | - }).catch((err)=>_reportError(ws, metadata, err, `Failed to read file at path ${fullPath}`)); |
| 258 | + // fs.promises.readFile is 40% slower than fs.readFile Though we noted only minor variations is our test |
| 259 | + // but fsNormal.readFile was faster most of the time though only by 10's of MS. |
| 260 | + // Leaving no quick fix performance on the table, so we moved to this impl. |
| 261 | + // https://github.com/nodejs/node/issues/37583 |
| 262 | + fsNormal.readFile(fullPath, (err, data)=>{ |
| 263 | + if(err) { |
| 264 | + _reportError(ws, metadata, err, `Failed to read file at path ${fullPath}`); |
| 265 | + return; |
| 266 | + } |
| 267 | + _sendResponse(ws, metadata, {}, toArrayBuffer(data)); |
| 268 | + }); |
262 | 269 | } |
263 | 270 |
|
264 | 271 | /** |
|
0 commit comments