Search code examples
iosjsonswiftmacosmetalkit

Can I encode and decode a JSON on the GPU using MetalKit?


I have this situation where my database is a huge JSON, to a point that decoding and encoding it takes too long and my user experience is harmed.

I am syncing my DB constantly with a device that is communicating via BLE, and the DB gets bigger with time.

I used MetalKit in the past to speed up image filtering, but I am not a pro metal programmer and do not have the tools to determine whether I can achieve decoding/encoding my JSON using metal.


Solution

  • The tasks that can be improved via GPU are the ones that can be parallelized. Since the GPU has many more cores than a CPU, a task that can be divided into smaller tasks (like image processing) are ideal for the GPU. The encoding and decoding of JSON is something that needs a lot of serial processing and in that scenario you should go throw the CPU.

    I can not see how you can efficiently parallelize the serialization and deserialization of a JSON. Maybe if your JSON has an array with lots of small elements (all with the same structure), maybe in that particular scenario using the GPU can improve the performance.