Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line reading slicing refactor #90

Merged
merged 3 commits into from
Jul 25, 2018
Merged

Conversation

ploxiln
Copy link
Contributor

@ploxiln ploxiln commented Jul 25, 2018

avoid allocating in MsgParser.Next() and simplify a few other byte slice things

adds a few benchmarks, and here are the overall results:

$ benchcmp old.txt new.txt 
benchmark                           old ns/op      new ns/op      delta
BenchmarkManyDifferentSensors-4     1335610085     1330076467     -0.41%
BenchmarkOneBigTimer-4              1218612245     1228443022     +0.81%
BenchmarkLotsOfTimers-4             1334108023     1323987632     -0.76%
BenchmarkMsgParserUDP-4             1553           1089           -29.88%
BenchmarkMsgParserTCP-4             1164           983            -15.55%
BenchmarkParseLineCounter-4         903            794            -12.07%
BenchmarkParseLineGauge-4           859            774            -9.90%
BenchmarkParseLineTimer-4           878            755            -14.01%
BenchmarkParseLineSet-4             812            704            -13.30%
BenchmarkPacketHandlerCounter-4     79.2           78.1           -1.39%
BenchmarkPacketHandlerGauge-4       70.3           70.1           -0.28%
BenchmarkPacketHandlerTimer-4       107            107            +0.00%
BenchmarkPacketHandlerSet-4         120            118            -1.67%

benchmark                           old allocs     new allocs     delta
BenchmarkManyDifferentSensors-4     35059          35060          +0.00%
BenchmarkOneBigTimer-4              33             35             +6.06%
BenchmarkLotsOfTimers-4             25019          25017          -0.01%
BenchmarkMsgParserUDP-4             20             15             -25.00%
BenchmarkMsgParserTCP-4             18             14             -22.22%
BenchmarkParseLineCounter-4         17             13             -23.53%
BenchmarkParseLineGauge-4           17             13             -23.53%
BenchmarkParseLineTimer-4           16             12             -25.00%
BenchmarkParseLineSet-4             16             12             -25.00%
BenchmarkPacketHandlerCounter-4     0              0              +0.00%
BenchmarkPacketHandlerGauge-4       0              0              +0.00%
BenchmarkPacketHandlerTimer-4       0              0              +0.00%
BenchmarkPacketHandlerSet-4         0              0              +0.00%

benchmark                           old bytes     new bytes     delta
BenchmarkManyDifferentSensors-4     1556808       1556872       +0.00%
BenchmarkOneBigTimer-4              1784          1896          +6.28%
BenchmarkLotsOfTimers-4             840472        840360        -0.01%
BenchmarkMsgParserUDP-4             2260          596           -73.63%
BenchmarkMsgParserTCP-4             863           549           -36.38%
BenchmarkParseLineCounter-4         536           440           -17.91%
BenchmarkParseLineGauge-4           496           432           -12.90%
BenchmarkParseLineTimer-4           592           464           -21.62%
BenchmarkParseLineSet-4             588           460           -21.77%
BenchmarkPacketHandlerCounter-4     0             0             +0.00%
BenchmarkPacketHandlerGauge-4       0             0             +0.00%
BenchmarkPacketHandlerTimer-4       80            80            +0.00%
BenchmarkPacketHandlerSet-4         65            65            +0.00%

(some variability due to running these on a laptop, and no changes should have caused the OneBigTimer allocation differences ...)

simplify MsgParser.Next()
 * use new MsgParser.newbuf for Read(), avoid make()
 * continue loop after EOF, avoid duplicate line logic

simplify MsgParser.lineFrom()
 * bytes.SplitN() works out better than bytes.SplitAfterN()

simplify parseLine() and sanitizeBucket()
 * can compare typeCode directly, instead of HasPrefix()
 * leave name as []byte, sanitize in-place
 * sanitize prefix and postfix once at startup

test bench shows fewer allocs and faster ops
@ploxiln ploxiln force-pushed the line_slice_refactor branch from 8adcbdd to f59aec2 Compare July 25, 2018 06:37
just 1.7.x and 1.10.x because statsdaemon is pretty simple
and we can assume versions in between will work fine
@jehiah jehiah merged commit 262a9ab into bitly:master Jul 25, 2018
@ploxiln
Copy link
Contributor Author

ploxiln commented Jul 25, 2018

Thanks for the review/merge!

@ploxiln ploxiln deleted the line_slice_refactor branch September 11, 2019 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants