parser: accelerate DecodingLayerParser#660
parser: accelerate DecodingLayerParser#660notti merged 2 commits intogoogle:masterfrom yerden:decoding-layer-container
Conversation
|
Sorry, force-pushed some changes, quite a few fixups came up. |
|
Test results on my laptop (Core i5-5300U) (all compared to the old implementation of DLP; last 3 compared to old implementation of DecodingLayerParserIgnorePanic) |
|
Hmm right now this looks like a lot code duplication: |
|
@notti thanks for the feedback. Unfortunately, as I stated earlier, attempt to make a single |
|
Hmm there is still 5 times the same function. I think there is no other way without loosing inlining/other optimizations. So last resort I could think of: how about generating the code like with gen2.go in layers? |
|
@notti thanks for the call, please see squashed revision. |
notti
left a comment
There was a problem hiding this comment.
Sorry for this last nitpick. With this last thing I'd say it is ready to merge. Thanks for the patience so far.
Changes:
* add DecodingLayerContainer to contain/search DecodingLayer values:
* add DecodingLayerFunc type as a decoder closure;
* add DecodingLayerMap, DecodingLayerSparse, DecodingLayerArray
as implementations of DecodingLayerContainer;
* add code generation for the reference LayersDecoder method
implementation.
* refactor DecodingLayerParser:
* use DecodingLayerMap by default;
* add SetDecodingLayerContainer method to initialize parser.
Signed-off-by: Yerden Zhumabekov <[email protected]>
Signed-off-by: Yerden Zhumabekov <[email protected]>
|
Windows tests were failing, I closed and reopened PR to trigger new build and they are fine now. A mystery. |
Yeah somehow travis ci is not completely reliable. Thanks for the contribution and patience with my requests. |
Not at all, thanks to you I learned some new tricks :) |
Before v1.1.18 passing an empty data slice to (*DecodingLayerParser).DecodeLayers would return a nil error. Commit 04f6565 (PR google#660) changed this behavior, passing the empty data to the to return an error from the first layer that considers an empty slice to be invalid. Strictly speaking this is an API breakage, so restore the previous behavior by returning nil straight away on empty data. Fixes google#846 Signed-off-by: Tobias Klauser <[email protected]>
Before v1.1.18 passing an empty data slice to (*DecodingLayerParser).DecodeLayers would return a nil error. Commit 04f6565 (PR google#660) changed this behavior, passing the empty data to the to return an error from the first layer that considers an empty slice to be invalid. Strictly speaking this is an API breakage, so restore the previous behavior by returning nil straight away on empty data. Fixes google#846 Signed-off-by: Tobias Klauser <[email protected]>
Hello, everyone,
This is a followup to #657.
I've investigated various ways to gain some extra performance for DecodingLayerParser. In the course of it, I was pursuing these goals:
So, I ended up adding DecodingLayerContainer which stores DecodingLayer values and allows to address them. Various implementations of DecodingLayerContainer are also presented: DecodingLayerMap, DecodingLayerSparse, DecodingLayerArray.
DecodingLayerParser is refactored to use DecodingLayerContainer. DecodingLayerMap is used by default in current implementation as the most versatile one. Additionally, new decoding logic omits redundant lookup of the first LayerType value. From another side, additional level of indirection may impose some overhead.
Of course, the user may write his/her own DecodingLayerContainer implementation if necessary. Those in need may refer to LayersDecoder function implementation in the package.
Here are benchmark results comparing with master branch, somewhat average value taken:
As you can see, the performance is nearly the same (or even slightly better) for default DecodingLayerMap container.
Some additional benchmarks added to test new containers:
As you can see, DecodingLayerSparse container is the fastest with standard LayerType values.
These three benchmarks show how DecodingLayerContainer may be used as a standalone layers decoding tool. As you can see, DecodingLayerParser with identical container imposes some additional overhead though adds some abstraction.
Tests were run on a laptop (Core i5-3320M), go 1.12.5. Please cross-check the results since I don't have access to another not heavily loaded physical machine.
Some caveat. LayersDecoder method in all presented DecodingLayerContainer implementations is a carbon copy of the package's LayersDecoder function so it leads to some code redundancy. It may be avoided simply by doing indirect call to LayersDecoder() but in that case the performance gains are not convincing that much. I believe it is so due to inlining done by compiler.