Skip to content

Commit e6a5643

Browse files
committed
chore: use fs.readfile instead of promises version for perfromance
1 parent f49ff32 commit e6a5643

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ By adopting Phoenix VFS, you're not just leveraging a file system; you're integr
4848
* [Example: Setting Up Your Own `phoenix-fs` Server in Node.js](#example-setting-up-your-own-phoenix-fs-server-in-nodejs)
4949
* [Development](#development)
5050
* [Tests in Browser](#tests-in-browser)
51+
* [Debug Symbols in tests.](#debug-symbols-in-tests)
5152
* [Tests in tauri](#tests-in-tauri)
5253
* [Publishing to npm](#publishing-to-npm)
5354
* [API Docs](#api-docs)

dist/phoenix-fs.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const WebSocket = require('ws');
22
const fs = require("fs/promises");
3+
const fsNormal = require("fs");
34
const path = require("path");
45
const os = require('os');
56
const { exec } = require('child_process');
67
const chokidar = require('chokidar');
7-
const anymatch = require('anymatch');
88
const ignore = require('ignore');
99
const crypto = require('crypto');
1010

@@ -255,10 +255,17 @@ function _stat(ws, metadata) {
255255

256256
function _readBinaryFile(ws, metadata) {
257257
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+
});
262269
}
263270

264271
/**

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)