bitly / statsdaemon

an implementation of Etsy's statsd in Go
The Unlicense
570 stars 131 forks source link

avoid using interface{} in Packet #81

Closed ploxiln closed 8 years ago

ploxiln commented 8 years ago

This is at least partly a subjective thing, which I tried mostly as an experiment, and I offer up in case there is agreement that it's not a bad idea:

instead of Value interface{}, have ValFlt float64, ValStr string

[pierce@plo-pro statsdaemon]$ go test -bench=Pa -run=none -benchtime 2s
PASS
BenchmarkParseLineCounter-4      2000000              1414 ns/op
BenchmarkParseLineGauge-4        2000000              1441 ns/op
BenchmarkParseLineTimer-4        2000000              1441 ns/op
BenchmarkParseLineSet-4          2000000              1361 ns/op
BenchmarkPacketHandlerCounter-4 20000000               134 ns/op
BenchmarkPacketHandlerGauge-4   20000000               152 ns/op
BenchmarkPacketHandlerTimer-4   20000000               181 ns/op
BenchmarkPacketHandlerSet-4     20000000               192 ns/op
ok      _/Users/pierce/scratch/statsdaemon      31.059s
[pierce@plo-pro statsdaemon]$ git checkout -
Switched to branch 'packet_no_interface'
[pierce@plo-pro statsdaemon]$ go test -bench=Pa -run=none -benchtime 2s
PASS
BenchmarkParseLineCounter-4      2000000              1360 ns/op
BenchmarkParseLineGauge-4        2000000              1333 ns/op
BenchmarkParseLineTimer-4        2000000              1394 ns/op
BenchmarkParseLineSet-4          2000000              1314 ns/op
BenchmarkPacketHandlerCounter-4 20000000               120 ns/op
BenchmarkPacketHandlerGauge-4   20000000               130 ns/op
BenchmarkPacketHandlerTimer-4   20000000               167 ns/op
BenchmarkPacketHandlerSet-4     20000000               174 ns/op
ok      _/Users/pierce/scratch/statsdaemon      28.837s
mreiferson commented 8 years ago

I'm +1 and a fan in general when there are known controlled types.

ploxiln commented 8 years ago

For what it's worth: I've been running this commit, which includes all of master, in production for about a week. It's been working.

Might be time for a release with support for floats 😁