Skip to content

Commit 04e7831

Browse files
committed
chore: maybe squeeze out a bit more read performance from node
1 parent b4dbe0c commit 04e7831

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@phcode/fs",
33
"description": "Phoenix virtual file system over filer/ browser fs access/ tauri / phoenix web socket APIs",
4-
"version": "2.0.3",
4+
"version": "2.0.4",
55
"keywords": [
66
"phoenix",
77
"browser",

src-tauri/node-src/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
/**

0 commit comments

Comments
 (0)