question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Very slow serialization of js function result

See original GitHub issue

Consider the script

function main(splash, args)
  f = splash:jsfunc([[
  function () {
    var result = []
    for (var i = 0; i < 5000; i++) {
      result.push({
         i_value: [i],
    	 const_value: 'foo',
      })
    }
    return result; // JSON.stringify(result);
  }  
  ]])
  s0 = splash:get_perf_stats()
  result = f()
  s1 = splash:get_perf_stats() 
  return {
    time=s1.walltime - s0.walltime,
    length=#result,
  }
end

this takes around 0.20 s. If we change the value to const_value: ['foo'], then time goes up to 0.25 – 0.30 s. If we return result as a JSON string instead (commented out) then it takes 0.05 – 0.07 s in both cases. So it looks like passing a big nested value from JS to the script is quite slow.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kmikecommented, Sep 26, 2019

It is for jsfunc, evaljs, wait_for_resume, maybe some other functions, so I think FAQ + links from individual functions in Lua API is good

0reactions
lopuhincommented, Sep 26, 2019

I think option 1 is good, another variant would be adding this to the jsfunc docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

slow serialization for some cases (happens in Node.js 10) #3
With some testing I found that setting the space option to something other than a value that results in no space fixes the...
Read more >
Crystal: slow json serialization of structs containing large strings
I'm wondering why json serialization of structs containing large strings is slow in Crystal. ... Considering Crystal is usually very fast (on par ......
Read more >
Sia: an ultra fast serializer in pure JavaScript | by Pouya Eghbali
Type checking is heavy, object and array creation is time consuming, but the most expensive and heaviest operation is working with strings.
Read more >
Serializing Complex Objects in JavaScript - Toptal
The JSON serializer is around 6-7 times slower than native serialization. The experimental protobufs serializer is around 13 times slower than the JSON ......
Read more >
Is postMessage slow? - surma.dev
The data shows that the complexity of the object is a strong factor in how long it takes to serialize and deserialize an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found