Friday 17 May 2013

Using web workers to JSON.parse large json files

Previously I had been working on converting FBX 3D animations to JSON to allow for easier loading of 3D animations into WebGL and OpenGL. However, using the standard JSON.parse JavaScript function is slow, and especially noticeable if you're running animations.

However, this noticeable lag can be combatted pretty easily with the use of webworkers. Instead of running the JSON.parse function on the main thread, just pass the unparsed string data over to a web worker and call JSON.parse there.

After implementing this change in the up coming realtime 3d games editor, around 1.8 seconds of unresponsive UI lag per ~4mb of json parsing was avoided.

You can find generalised implementation up on github for your royalty free, do whatever you want with it, and don't blame me for crashes, use.

Download: json.async

Video walkthrough

No comments:

Post a Comment