SharedMap icon indicating copy to clipboard operation
SharedMap copied to clipboard

Maximum call stack size exceeded on large strings.

Open RichAyotte opened this issue 3 years ago • 3 comments

With large value such as:

const sharedMap = new SharedMap(176, 70, 4239148)

The following error is thrown when I attempt to get the value with sharedMap.get('some_key')

[00:33:12] ERROR (496227 on exopad): Maximum call stack size exceeded
    err: {
      "type": "RangeError",
      "message": "Maximum call stack size exceeded",
      "stack":
          RangeError: Maximum call stack size exceeded
              at SharedMap._decodeValue (/home/rich/Projects/@exodus/exchange-server/node_modules/sharedmap/index.umd.js:320:39)
              at SharedMap.get (/home/rich/Projects/@exodus/exchange-server/node_modules/sharedmap/index.umd.js:538:39)
              at forRatesToBeWrittenToRedis (/home/rich/Projects/@exodus/exchange-server/src/backend/for-rates-to-be-written-to-redis.ts:35:60)
              at forRates (/home/rich/Projects/@exodus/exchange-server/src/backend/provider-worker.ts:110:37)
              at processTicksAndRejections (node:internal/process/task_queues:96:5)
              at async MessagePort.<anonymous> (/home/rich/Projects/@exodus/exchange-server/src/backend/provider-worker.ts:140:7)
    }

RichAyotte avatar Dec 20 '21 05:12 RichAyotte

_decodeValue uses String.fromCharCode which requires that the whole string fits in the stack - as opposed as just a reference.

While this can be easily fixed, I think that, performance-wise, it is definitely a bad idea to store 4MB strings in the SharedMap.

mmomtchev avatar Dec 20 '21 11:12 mmomtchev

Storing massive strings is probably a bad idea. I'm going to explore other ideas. Feel free to close.

RichAyotte avatar Dec 20 '21 16:12 RichAyotte

I will keep it open as performance can be improved even for small strings by using ArrayBuffer instead of a character by character conversion The problem is that it will be Node.js-only - which means that the old method will have to be preserved for the browser - as at least in theory SharedMap could be used in the browser too

mmomtchev avatar Dec 20 '21 16:12 mmomtchev