Skip to content

Commit f4855d2

Browse files
authored
docs: expand README with 'How does it work' section
Added a section explaining how Hyper-FS works with Rust and included diagrams for comparison with Node.js.
1 parent cf97abe commit f4855d2

File tree

1 file changed

+65
-10
lines changed

1 file changed

+65
-10
lines changed

README.md

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
<div align="center">
2+
13
# Hyper-FS
2-
3-
<p align="center">
4-
<img src="https://img.shields.io/badge/Written%20in-Rust-orange?style=flat-square" alt="Written in Rust">
5-
<img src="https://img.shields.io/npm/v/hyper-fs?style=flat-square" alt="NPM Version">
6-
<img src="https://img.shields.io/npm/l/hyper-fs?style=flat-square" alt="License">
7-
</p>
8-
9-
<p align="center">
10-
A high-performance, drop-in replacement for Node.js <code>fs</code> module, powered by Rust.
11-
</p>
4+
5+
<p align="center">
6+
<img src="https://img.shields.io/badge/Written%20in-Rust-orange?style=flat-square" alt="Written in Rust">
7+
<img src="https://img.shields.io/npm/v/hyper-fs?style=flat-square" alt="NPM Version">
8+
<img src="https://img.shields.io/npm/l/hyper-fs?style=flat-square" alt="License">
9+
</p>
10+
11+
<p align="center">
12+
A high-performance, drop-in replacement for Node.js <code>fs</code> module, powered by Rust.
13+
</p>
14+
</div>
1215

1316
## Installation (⚠️ Not Ready Yet)
1417

@@ -18,6 +21,58 @@ npm install hyper-fs
1821
pnpm add hyper-fs
1922
```
2023

24+
## How does it works
25+
26+
For the original Node.js, it works serially and cost lots of memory to parse os object and string into JS style:
27+
28+
```mermaid
29+
graph TD
30+
A["JS: readdir"] -->|Call| B("Node.js C++ Binding")
31+
B -->|Submit Task| C{"Libuv Thread Pool"}
32+
33+
subgraph "Native Layer (Serial)"
34+
C -->|"Syscall: getdents"| D[OS Kernel]
35+
D -->|"Return File List"| C
36+
C -->|"Process Paths"| C
37+
end
38+
39+
C -->|"Results Ready"| E("V8 Main Thread")
40+
41+
subgraph "V8 Interaction (Heavy)"
42+
E -->|"Create JS String 1"| F[V8 Heap]
43+
E -->|"String 2"| F
44+
E -->|"String N..."| F
45+
F -->|"GC Pressure Rising"| F
46+
end
47+
48+
E -->|"Return Array"| G["JS Callback/Promise"]
49+
```
50+
51+
But, it's saved with Rust now:
52+
53+
```mermaid
54+
graph TD
55+
A["JS: readdir"] -->|"N-API Call"| B("Rust Wrapper")
56+
B -->|"Spawn Thread/Task"| C{"Rust Thread Pool"}
57+
58+
subgraph "Rust 'Black Box'"
59+
C -->|"Rayon: Parallel work"| D[OS Kernel]
60+
D -->|"Syscall: getdents"| C
61+
C -->|"Store as Rust Vec<String>"| H[Rust Heap]
62+
H -->|"No V8 Interaction yet"| H
63+
end
64+
65+
C -->|"All Done"| I("Convert to JS")
66+
67+
subgraph "N-API Bridge"
68+
I -->|"Batch Create JS Array"| J[V8 Heap]
69+
end
70+
71+
J -->|Return| K["JS Result"]
72+
```
73+
74+
75+
2176
## Status & Roadmap
2277

2378
We are rewriting `fs` APIs one by one.

0 commit comments

Comments
 (0)