Compression in SwiftNIO

I have a TCP-Server-Client setup. On the server I have a MongoDB instance, so I send the JSON data to the client, that decodes it. It is working, but the more data I have, the slower it gets. Especially because the property names are not quite short, I will have a lot data, when I send multiple data entries.

Example (imagine hundreds of those entries):

		"priority": "high",
		"dueDate": 626605206.32999992,
		"fileId": ".............",
		"isDone": true,
		"taskDescription": "Do this and that",
		"taskTypeId": ".............",

So I thought about compression. Are there any common and working techniques in SwiftNIO or do I need to implement sth. by myself? If so, where can I start? (I don't want to use Apples Compression framework, because it's not working on Linux).

A quick google gives GitHub - adam-fowler/compress-nio: Compression/Decompression support for Swift NIO ByteBuffer ?

There's no standard solution because many compression algorithms are not self-framing: it's not necessarily easy to determine where the boundaries between messages are.

However, you can easily define such a framing layer yourself (length-prefixed is usually fine), and then any compression framework you choose to use will work well.

Thank you very much! I found compress-nio as well, but I was wondering, if there are some good hints what I can consider too. But after reading your answers, it may be better to leave it out of SwiftNIO and instead I should compress/decompress the String I will write to the ByteBuffer before sending it via client and server.

Terms of Service

Privacy Policy

Cookie Policy