Skip to content

Don't try to grow the buffer more than allowed by the system#75

Open
targos wants to merge 3 commits into
mainfrom
ensure-available
Open

Don't try to grow the buffer more than allowed by the system#75
targos wants to merge 3 commits into
mainfrom
ensure-available

Conversation

@targos

@targos targos commented Feb 1, 2025

Copy link
Copy Markdown
Member
  • refactor: move endianness check to separate file
  • fix: don't try to grow the buffer more than allowed by the system

Closes: image-js/fast-png#42

@codecov

codecov Bot commented Feb 1, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9a39938) to head (0d1486a).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #75   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         3    +1     
  Lines          337       378   +41     
  Branches        75        84    +9     
=========================================
+ Hits           337       378   +41     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@targos

targos commented Feb 1, 2025

Copy link
Copy Markdown
Member Author

I don't know how to reliably detect what is the maximum size for a typed array. Since Node.js 22, there is no arbitrary limit in V8.
On macOS, what I pushed here works because the memory is not really allocated (it's in the virtual space), but on Linux it's real and makes the process crash when we try too high.

@lpatiny Any idea?

@lpatiny

lpatiny commented Feb 1, 2025

Copy link
Copy Markdown
Member

Maybe using on node

> require('v8').getHeapStatistics()
{
  total_heap_size: 543752192,
  total_heap_size_executable: 524288,
  total_physical_size: 543752192,
  total_available_size: 3804536944,
  used_heap_size: 541746816,
  heap_size_limit: 4345298944,
  malloced_memory: 278632,
  peak_malloced_memory: 874496,
  does_zap_garbage: 0,
  number_of_native_contexts: 1,
  number_of_detached_contexts: 0,
  total_global_handles_size: 12800,
  used_global_handles_size: 4512,
  external_memory: 2312309
}
> var b=new Array(2**26).fill(0).map(Math.random)
undefined
> require('v8').getHeapStatistics()
{
  total_heap_size: 3260137472,
  total_heap_size_executable: 524288,
  total_physical_size: 3260137472,
  total_available_size: 1102417256,
  used_heap_size: 3225912760,
  heap_size_limit: 4345298944,
  malloced_memory: 278632,
  peak_malloced_memory: 874496,
  does_zap_garbage: 0,
  number_of_native_contexts: 1,
  number_of_detached_contexts: 0,
  total_global_handles_size: 12800,
  used_global_handles_size: 4608,
  external_memory: 2312293
}

and in the browser

performance.memory.jsHeapSizeLimit
performance.memory.totalJSHeapSize

Actually this is something very important also in nmr-load-save so if we have a package that is node / browser compatible it would be very usefull.

@targos

targos commented Feb 1, 2025

Copy link
Copy Markdown
Member Author

I'm not sure the js heap size is relevant. ArrayBuffer data are notably not counted in it.

@targos

targos commented Feb 1, 2025

Copy link
Copy Markdown
Member Author

And in browsers, the typed array size limit is unrelated to the memory limit. It's arbitrarily chosen by the browser.

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.

RangeError: Array buffer allocation failed

2 participants