2 ms·
Twice as fast over the standard library is damn impressive, I wonder where the performance gains were found?
by hydroxideOH- 6y ago
Twice as fast over the standard library is damn impressive, I wonder where the performance gains were found?
- superwhiskers 6y agothe main things that make it faster come down to: - the api doesn't care about compatibility with the standard library at all (interface-wise), allowing a little more flexibility in interface presentation, which can allow for some performance improvements - the implementations are small and not as large as `bytes.Buffer`'s, which also aid in making it fast (just look at all that `bytes.Buffer` does to write data: https://golang.org/src/bytes/buffer.go#L168 https://golang.org/src/bytes/buffer.go#L168) - i try to bypass safety checks where possible and feasible (such as when indexing, by using `unsafe.Pointer`) which, doesn't speed it up much, but it's full of unnecessary/unidiomatic code optimizations already, i don't think more would be too much of an issue :p that's probably all of the big things. there's also other design decisions like choosing to generate implementations of what would be redundant instead of providing a consolidated implementation like i had done before (as seen with the complex r/w methods), and other really small micro-optimizations that i touched it off with that probably don't help much but i was honestly trying to find whatever i could just to make it faster