Commit 77fd089
⚡ Stream-decode Windows firewall rules to reduce memory (#7099)
* ⚡ stream-decode Windows firewall rules and profiles JSON
Replace io.ReadAll + json.Unmarshal with json.NewDecoder streaming
in ParseWindowsFirewallRules and ParseWindowsFirewallProfiles. This
avoids holding the entire raw byte buffer and the parsed struct slice
in memory simultaneously, roughly halving peak memory usage on machines
with thousands of firewall rules.
Also handles the PowerShell single-object edge case where exactly one
rule/profile is emitted as a bare {} instead of [{}].
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* ⚡ address review: validate token, use MultiReader, extract generic helper
- Validate that a non-array token is actually '{' before treating it as
a single object; return a clear error for unexpected tokens (null, etc.)
- Use io.MultiReader instead of manual byte splicing to avoid intermediate
allocations in the single-object fallback path
- Extract streamDecodeJSONArray[T] generic helper to deduplicate the
identical logic between ParseWindowsFirewallRules and
ParseWindowsFirewallProfiles
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent d896886 commit 77fd089
1 file changed
+45
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | | - | |
37 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
45 | 67 | | |
46 | 68 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 69 | + | |
| 70 | + | |
51 | 71 | | |
52 | 72 | | |
53 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
54 | 88 | | |
55 | 89 | | |
56 | 90 | | |
| |||
119 | 153 | | |
120 | 154 | | |
121 | 155 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 156 | + | |
139 | 157 | | |
0 commit comments