Avoid allocating memory for entire swf file in format.swf.Writer
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- performance
Research direction
Start in format/swf/Writer.hx around lines 1450-1452, where the full SWF-sized memory block is allocated. Review the Haxe swfParser.ml example for determining the SWF size in advance, then examine how Compress.execute can process buffer chunks. Done means large SWFs no longer require a monolithic allocation and compression call at the end.
Written by the indexing model from the issue text.
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:
- 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.
- 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.
- Dominant language
- Haxe
- Stars
- 141
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HaxeFoundation/format
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
HaxeFoundation/format#111 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
HaxeFoundation/format#102 · 5 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
HaxeFoundation/format#100 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
HaxeFoundation/format#99 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
HaxeFoundation/format#98 · 2 comments ·
All issues in HaxeFoundation/format
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
blacklanternsecurity/bbot#3679 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
sync cache dist/imgOpen
Difficulty 1/5 Under an hour Newbie friendliness 82/100
oleeskild/digitalgarden#435 ·
-
Optimize formulaArg struct memory layout to reduce formula matrix allocationPossibly taken @shcabin claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 6 days
-
Cache AI SummaryOpen
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
SimonHalvdansson/Harmonic-HN#432 ·