atilaneves / cerealed

Powerful binary serialisation library for D
BSD 3-Clause "New" or "Revised" License
92 stars 3 forks source link

Performance boost #6

Closed tchaloupka closed 9 years ago

tchaloupka commented 9 years ago

Hi, as I worked on MQTT client library[0], I've found forum post about cerealed's speed[1], so I tried to make my "just mqtt" serialization as fast as msgpack and trying that I found some ways to improve performance of cerealed in specific cases and decided to make a PR for it.

I took your provided benchmark [2] and made some tuning for strings and byte arrays.

The test went from (DMD debug): Cerealed: 5 secs, 926 ms, 824 μs, and 5 hnsecs MsgPack: 2 secs, 226 ms, 575 μs, and 3 hnsecs

To: Cerealed: 2 secs, 667 ms, 188 μs, and 3 hnsecs MsgPack: 2 secs, 159 ms, 598 μs, and 1 hnsec

Which I like, so I hope this helps somehow. There are probably some other possible ways to tune it a bit more for other cases too.

[0] https://github.com/chalucha/vibe-mqtt [1] http://forum.dlang.org/post/kceyzhlcumjxlfwbhcfr@forum.dlang.org [2] http://dpaste.dzfl.pl/17b0ed9c0204

atilaneves commented 9 years ago

Interesting, this was already along the lines of what I wanted to do. Unfortunately, the code doesn't even compile with this patch (Travis is acting up so I downloaded the patch, applied it manually and tried running the UTs). I'll do a commit in a few min that will allow you to run them youself with dub test. Please rebase your PR then and fix the issue. Thanks!

atilaneves commented 9 years ago

I had time so I took a look: the issue is on line 89 when casting val to ubyte[]. Sometimes val in that case is a range and not an array, so simply appending .array to val there makes it compile and successfully run the tests. I'll let you fix your PR then I can merge, so you can get the credit in the git history. Thanks!

tchaloupka commented 9 years ago

Hi, I've added the to array fix, it compiles fine, but at least for me one of the tests fails: tests.encode.testEncodeAssocArray: tests/encode.d:117 - Expected: [0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 6] tests/encode.d:117 - Got: [0, 2, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 1, 0, 0, 0, 2]

I didn't touch AAs serialization so I hope it isn't caused by this.

atilaneves commented 9 years ago

Weird, not only does it pass for me, as you can see from this page it passes on Travis as well. I'll merge it anyway. What's your OS / architecture / etc. ? A failing test is... not good. But I can't reproduce the issue.