@@ -72,6 +72,58 @@ graph TD
7272 J -->|Return| K["JS Result"]
7373```
7474
75+ ## How does it works
76+
77+ For the original Node.js, it works serially and cost lots of memory to parse os object and string into JS style:
78+
79+ ``` mermaid
80+ graph TD
81+ A["JS: readdir"] -->|Call| B("Node.js C++ Binding")
82+ B -->|Submit Task| C{"Libuv Thread Pool"}
83+
84+ subgraph "Native Layer (Serial)"
85+ C -->|"Syscall: getdents"| D[OS Kernel]
86+ D -->|"Return File List"| C
87+ C -->|"Process Paths"| C
88+ end
89+
90+ C -->|"Results Ready"| E("V8 Main Thread")
91+
92+ subgraph "V8 Interaction (Heavy)"
93+ E -->|"Create JS String 1"| F[V8 Heap]
94+ E -->|"String 2"| F
95+ E -->|"String N..."| F
96+ F -->|"GC Pressure Rising"| F
97+ end
98+
99+ E -->|"Return Array"| G["JS Callback/Promise"]
100+ ```
101+
102+ But, it's saved with Rust now:
103+
104+ ``` mermaid
105+ graph TD
106+ A["JS: readdir"] -->|"N-API Call"| B("Rust Wrapper")
107+ B -->|"Spawn Thread/Task"| C{"Rust Thread Pool"}
108+
109+ subgraph "Rust 'Black Box'"
110+ C -->|"Rayon: Parallel work"| D[OS Kernel]
111+ D -->|"Syscall: getdents"| C
112+ C -->|"Store as Rust Vec<String>"| H[Rust Heap]
113+ H -->|"No V8 Interaction yet"| H
114+ end
115+
116+ C -->|"All Done"| I("Convert to JS")
117+
118+ subgraph "N-API Bridge"
119+ I -->|"Batch Create JS Array"| J[V8 Heap]
120+ end
121+
122+ J -->|Return| K["JS Result"]
123+ ```
124+
125+
126+
75127## Status & Roadmap
76128
77129We are rewriting ` fs ` APIs one by one.
0 commit comments