text-encoding icon indicating copy to clipboard operation
text-encoding copied to clipboard

Large memory usage

Open jeromegn opened this issue 6 years ago • 1 comments

We've noticed the heap goes way up when decoding large array buffers (uint8array) into a utf-8 string.

We're using text-encoding in @fly/fly (a way to run Service Worker-like code in v8 to handle http requests) and it's a life saver. Re-implementing all that logic would've been a pain.

Decoding a ~1.5MB array buffer into a UTF-8 string brings the heap up ~60MB in v8.

More precisely, I'm doing:

  • a fetch to a resource weighing in at 1.5MB
  • concatenating it to a single Uint8Array
  • decoding it with this package

This happens around here: https://github.com/superfly/fly/blob/master/v8env/body.js#L53-L59

I'm measuring heap before and after the decoding and that's when the huge increase of memory seems happens.

Maybe this is normal, I'm not sure. It seems off to me that it would consume so much memory. In any case, I'd love to know more about the expected memory usage of this package.

jeromegn avatar Feb 16 '18 14:02 jeromegn

It's really just a reference implementation, not designed for production use. No assertions are made about memory usage.

inexorabletash avatar Sep 28 '18 04:09 inexorabletash