Skip to content

Commit e5861a2

Browse files
committed
perf(ipc): skip drain
1 parent 3113f02 commit e5861a2

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
## motivation
2525

2626
I want to know the folder size quickly, but the nodejs implementation of
27-
[get-folder-size](https://github.com/alessioalex/get-folder-size) is slow, so using
28-
go implements a recursive get folder size that runs in nodejs and is `7 ~ 20` times faster than the node native solution under normal circumstances。
27+
[get-folder-size](https://github.com/alessioalex/get-folder-size) is slow, so
28+
using go implements a recursive get folder size that runs in nodejs and is
29+
`7 ~ 20` times faster than the node native solution under normal circumstances。
2930

3031
<br />
3132

README_ZH.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
想要快速知道文件夹大小,但 nodejs 实现的
2121
[get-folder-size](https://github.com/alessioalex/get-folder-size) 是慢的,所以用
22-
go 实现了递归获取文件夹大小,能跑在 nodejs 中,正常情况下,比 node 原生方案快 `7 ~ 20`
22+
go 实现了递归获取文件夹大小,能跑在 nodejs 中,正常情况下,比 node 原生方案快
23+
`7 ~ 20`
2324

2425
具体可见 issue 👉
2526
[get-folder-size/issues/22](https://github.com/alessioalex/get-folder-size/issues/22)

bench.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66

77
const { getFolderSizeWithIpc, close } = createGetFolderSizeBinIpc();
88

9-
const base = "./";
9+
const base = "../";
1010

1111
const nodeStartTime = Date.now();
1212
const nodeResult = await getFolderSize(base, true);

src/bin.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function getFolderSizeBin(
8585
});
8686

8787
if (stderr) {
88-
throw new Error(stderr)
88+
throw new Error(stderr);
8989
}
9090

9191
if (pretty) {
@@ -95,9 +95,7 @@ export async function getFolderSizeBin(
9595
return Number(stdout);
9696
}
9797

98-
export function createGetFolderSizeBinIpc(
99-
options: Options = {},
100-
) {
98+
export function createGetFolderSizeBinIpc(options: Options = {}) {
10199
const { binPath = detectDefaultBinPath(), loose = false } = options;
102100

103101
let tasks = new Map<
@@ -128,17 +126,18 @@ export function createGetFolderSizeBinIpc(
128126
let full = false;
129127
function send(base: string) {
130128
if (full) {
131-
return go.stdin.once("drain", () => go.stdin.write(`${base},`));
129+
return go.stdin.once("drain", () => {
130+
full = false;
131+
go.stdin.write(`${base},`);
132+
});
132133
}
133134
full = !go.stdin.write(`${base},`);
134135
}
135136

136137
readline.on("line", (item: string) => {
137138
const [base, size] = item.split(",");
138139
const { pretty, resolve } = tasks.get(base);
139-
resolve(
140-
pretty ? prettyBytes(Number(size)) : Number(size),
141-
);
140+
resolve(pretty ? prettyBytes(Number(size)) : Number(size));
142141
tasks.delete(base);
143142
});
144143

wasm/main.wasm

102 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)