Skip to content

fix(memory): replace slice with subarray to optimise memory usage - #28

Open
piyu-sh wants to merge 1 commit into
yusitnikov:masterfrom
piyu-sh:master
Open

fix(memory): replace slice with subarray to optimise memory usage#28
piyu-sh wants to merge 1 commit into
yusitnikov:masterfrom
piyu-sh:master

Conversation

@piyu-sh

@piyu-sh piyu-sh commented Oct 3, 2025

Copy link
Copy Markdown

slice creates a copy of arraybuffer due to which unnecessary memory is allocated, if we replace it with subarray which only creates a read only view, it lowers the memory usage by 100%.
In this case this.data is only read from so imo its safe to use subarray but might need more testing of edge cases.

I tested for a sample ~2gb file in demo, earlier memory usage was around ~6.5gb, after the change it dropped to ~4.5gb, almost the same amount as that of file size

before change
image

after change
image

@piyu-sh

piyu-sh commented Oct 3, 2025

Copy link
Copy Markdown
Author

@yusitnikov please check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant