Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded on large strings. #12

Open
RichAyotte opened this issue Dec 20, 2021 · 3 comments
Open

Maximum call stack size exceeded on large strings. #12

RichAyotte opened this issue Dec 20, 2021 · 3 comments

Comments

@RichAyotte
Copy link

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)
    }
@mmomtchev
Copy link
Owner

_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.

@RichAyotte
Copy link
Author

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

@mmomtchev
Copy link
Owner

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

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

No branches or pull requests

2 participants