Hacker News new | ask | show | jobs
by duncanawoods 4186 days ago
What would you suggest for this situation:

a low priority admin page renders a 3000 row, 30 col table on the server using react. The query and resulting page size are pretty small < 2MB but this takes 5s for react to render.

I didn't expect it to be this slow and can't use client side rendering.

2 comments

Those type of frameworks are great, but they all have performance limitations. The typical solutions are either find a faster framework or write it by hand. If the issue is that it is blocking the event loop rather than the literal performance, then you could spawn a process to do the React work.
Thanks. Are there no background worker process packages for nodejs that might be able to queue up some tasks?
You want to search for "web worker" or "background task" in NPM.

One example: https://github.com/audreyt/node-webworker-threads

You could break it up so that it processes the 3000 rows in chunks of say.. 500, and use process.nextTick() between each chunk to ensure node is handling other events too.
That would block a server for 500ms six times which is still unacceptable let alone being a hack that would mean rewriting the react page to support partial evaluation.

Your suggestion is basically to write your own event loop and write any cpu bound task to manually yield to the single-threaded node event loop. Crazy given we have been using multithreaded servers for decades that would do this automatically and generalise for any cpu-bound task.