FIX is the protocol that moves orders and quotes between brokers, exchanges and trading firms. QuickFIX/Go is a widely used Go implementation of it. Every price and quantity on every outgoing message passes through one small function, so I went looking at what it costs.
Status: the change is open as quickfixgo/quickfix#787 , discussed in #786 . I'll update this post if it changes in review.
The function
FIXDecimal.Write turns a decimal into the bytes that go on the wire:
func ( d FIXDecimal ) Write () [] byte { return [] byte ( d . Decimal . StringFixed ( d . Scale )) }
Enter fullscreen mode
Exit fullscreen mode
It looks harmless. The benchmark says otherwise:
BenchmarkFIXDecimalWrite 155 ns/op 208 B/op 11 allocs/op
Enter fullscreen mode
Exit fullscreen mode
Eleven heap allocations to format -124.3456 . StringFixed rounds through big.Int arithmetic, builds intermediate strings, and then the result is copied again into a []byte .…