0

Is there any fastest way to calculate JS object size is greater than some small size (256kb).I can caputure it via some NPM or some rough method like How to get the size of a JavaScript object?

But as you know If I calculate some big file size eg:10 MB file It will die out memory for calculating some 10-1000 objects when it comes to bulk. I think of when ever it seems reach more than 256kb then it should stop further calculation of that file size and send as file is greater than that value.

OR

is that suggested method of calculating object size is working very fast enough for use in bulk operation ?

Here is my real problem:

I'm have some JS object (aws SES mail parameters) I have created a mail delivery pipeline via SQS for sending emails as for Rate limiting as this is bulk operation lead to aws SES rate limiting. But here aws SQS has problem like it only can hold less than 256 kb size object. for before put it into the queue I need to get JS object param size and make decision on whether I can be able to sent it to queue or not.

Prageeth godage
  • 4,054
  • 3
  • 29
  • 45
  • 1
    [``Buffer``](https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html) won't work here, right? – Take-Some-Bytes Jul 21 '20 at 17:07
  • 2
    What exactly are you trying to accomplish? The "size" of a Javascript object is completely dependent upon the JS engine implementation and, in fact, it can even vary depending upon what happened to the object before it arrived in this condition (some objects are optimized in some ways with C++ like "classes"). Some arrays are optimized into C++ like arrays if they never had holes and always had the same type stored in them. – jfriend00 Jul 21 '20 at 21:24
  • 1
    Please show your actual code and describe what you're trying to accomplish. We can likely advise on ways to reduce memory usage in processing some large file without calculating object sizes. – jfriend00 Jul 21 '20 at 21:25
  • @jfriend00 updated the question.thanks for your ideas really helpful.so you clear on what my problem is ? – Prageeth godage Jul 22 '20 at 03:21
  • 1
    “make decision on whether I can be able to sent it to queue or not” - is this serialized (eg. JSON) data? If so, a jsonStr.length might be suitable for some heuristic of ‘size’. – user2864740 Jul 22 '20 at 03:46
  • This just sounds like SQS isn't really the right tool for you if you can't live with it's limitations. – jfriend00 Jul 22 '20 at 04:28
  • For large file,I have alternative path like SQS large file integration witch will be costly as per S3 bucket comes to play.So I need to have a decision based on size.It rather like router based on size.if less size goes to normal sqs – Prageeth godage Jul 22 '20 at 04:41
  • Friends,As I draw to conclusion like there is no guaranteed way of calculating the size of the JS object in quicker way and have to find alternative path like change the design,you guys agree with me ? – Prageeth godage Jul 22 '20 at 04:46

0 Answers0