feat(performance): removed double memory usage when reading/writing text files#2359
Conversation
Greptile SummaryThis PR eliminates the base64 encode/decode round-trip that previously doubled memory usage when reading and writing text files on external storage. Two new native paths (
Confidence Score: 5/5Safe to merge; the new native text paths behave correctly for all standard encodings. The read and write paths correctly handle charset resolution, BOM stripping, and JSON parsing. The The Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant JS as JavaScript (externalFs.js)
participant Bridge as Cordova Bridge
participant Java as SDcard.java
Note over JS,Java: OLD read path (double memory)
JS->>Bridge: sdcard.read(url) to ArrayBuffer via base64
Bridge->>Java: read action
Java-->>Bridge: byte[] as base64 String
Bridge-->>JS: ArrayBuffer
JS->>JS: decode(buffer, charset) to String 2x memory
Note over JS,Java: NEW read path (single pass)
JS->>Bridge: sdcard.readAsText(url, charset)
Bridge->>Java: readAsText action
Java->>Java: InputStreamReader(is, charset) to String
Java-->>Bridge: String
Bridge-->>JS: String
JS->>JS: BOM strip then return text
Note over JS,Java: NEW write path (single pass)
JS->>Bridge: sdcard.writeText(url, text, charset)
Bridge->>Java: writeText action
Java->>Java: content.getBytes(charset) then write to disk
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant JS as JavaScript (externalFs.js)
participant Bridge as Cordova Bridge
participant Java as SDcard.java
Note over JS,Java: OLD read path (double memory)
JS->>Bridge: sdcard.read(url) to ArrayBuffer via base64
Bridge->>Java: read action
Java-->>Bridge: byte[] as base64 String
Bridge-->>JS: ArrayBuffer
JS->>JS: decode(buffer, charset) to String 2x memory
Note over JS,Java: NEW read path (single pass)
JS->>Bridge: sdcard.readAsText(url, charset)
Bridge->>Java: readAsText action
Java->>Java: InputStreamReader(is, charset) to String
Java-->>Bridge: String
Bridge-->>JS: String
JS->>JS: BOM strip then return text
Note over JS,Java: NEW write path (single pass)
JS->>Bridge: sdcard.writeText(url, text, charset)
Bridge->>Java: writeText action
Java->>Java: content.getBytes(charset) then write to disk
Reviews (6): Last reviewed commit: "format" | Re-trigger Greptile |
No description provided.