Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: maybe squeeze out a bit more read performance from node #43

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@phcode/fs",
"description": "Phoenix virtual file system over filer/ browser fs access/ tauri / phoenix web socket APIs",
"version": "2.0.3",
"version": "2.0.4",
"keywords": [
"phoenix",
"browser",
Expand Down
17 changes: 12 additions & 5 deletions src-tauri/node-src/phoenix-fs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const WebSocket = require('ws');
const fs = require("fs/promises");
const fsNormal = require("fs");
const path = require("path");
const os = require('os');
const { exec } = require('child_process');
const chokidar = require('chokidar');
const anymatch = require('anymatch');
const ignore = require('ignore');
const crypto = require('crypto');

Expand Down Expand Up @@ -255,10 +255,17 @@ function _stat(ws, metadata) {

function _readBinaryFile(ws, metadata) {
const fullPath = metadata.data.path;
fs.readFile(fullPath)
.then(data => {
_sendResponse(ws, metadata, {}, toArrayBuffer(data));
}).catch((err)=>_reportError(ws, metadata, err, `Failed to read file at path ${fullPath}`));
// fs.promises.readFile is 40% slower than fs.readFile Though we noted only minor variations is our test
// but fsNormal.readFile was faster most of the time though only by 10's of MS.
// Leaving no quick fix performance on the table, so we moved to this impl.
// https://github.com/nodejs/node/issues/37583
fsNormal.readFile(fullPath, (err, data)=>{
if(err) {
_reportError(ws, metadata, err, `Failed to read file at path ${fullPath}`);
return;
}
_sendResponse(ws, metadata, {}, toArrayBuffer(data));
});
}

/**
Expand Down
Loading