Commit dc1318f
Optimize ToFlatOpcString to reduce memory usage and improve performan… (#1863)
## Optimized the ToFlatOpcString method to address high memory usage and
improve performance.
The previous implementation relied on LINQ, which created a significant
amount of intermediate collections and dictionaries, leading to
inefficiency, especially when working with Word documents containing
images.
This update removes unnecessary LINQ operations and reduces memory
overhead, replace manual chunking logic with Convert.ToBase64String
using Base64FormattingOptions.InsertLineBreaks.
This approach eliminates the need for LINQ-based chunking and
aggregation, resulting in cleaner, more efficient code while adhering to
the MIME specification for line breaks in Base64 encoding.
A sample benchmark output when working with a 822KB-word document.

Co-authored-by: Dat Hoang Quoc <[email protected]>
Co-authored-by: Taylor Southwick <[email protected]>1 parent ed521b6 commit dc1318f
File tree
1 file changed
+1
-19
lines changed- src/DocumentFormat.OpenXml.Framework/Packaging
1 file changed
+1
-19
lines changedLines changed: 1 addition & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 144 | + | |
163 | 145 | | |
164 | 146 | | |
165 | 147 | | |
| |||
0 commit comments