HaxeFoundation / HaxeFoundation/format
Avoid allocating memory for entire swf file in format.swf.Writer
- Dominant language
- Haxe
- Stars
- 139
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
Currently, when running `format.swf.Writer`, at the end, a memory block the size of the entire swf file is allocated: https://github.com/HaxeFoundation/format/blob/318e49a55f45a836b3fd8ab41215f3649046dfa8/format/swf/Writer.hx#L1450-L1452
This can cause issues with large swfs, for example: https://github.com/openfl/lime/issues/1307.
A possible better solution is to:
1. Work out the size of the swf in advance, so we don't need to wait until the large byte buffer has been filled to figure out the length for the header. Here is some example code from the haxe repo that does this: https://github.com/HaxeFoundation/haxe/blob/731dcd71f10c495a5a820449249fbb3d4b40a7c1/libs/swflib/swfParser.ml#L2062-L2066.
2. When the byte buffer exceeds a certain size, send the current bytes to the compression stream (using Compress.execute). The compressed bytes can be written to the file, and we can continue with emptied buffers. This removes the need for a monolithic allocation and compression call at the end.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.