In our project we do thousands of printer.Print calls per second, so its performance is critical for us.
As it is, printer.Print is rather slow, see issue #674 for some comparisons.
This is caused by its use of json.Marshal and json.Unmarshal as a way of converting interfaces to map[string]interface{} in the convertMap method.
This PR replaces the JSON logic with a custom, reflection based converter instead.
It also adds a benchmark to measure the performance impact.
coverage: 92.051%. remained the same when pulling 732b137605d9211d9288d47eebb585d7fabe8950 on adelsz:faster-printer-print into 4ebf270b92df8ca6b2eb2ed97e595e642dee9b0a on graphql-go:master.
In our project we do thousands of
printer.Print
calls per second, so its performance is critical for us.As it is,
printer.Print
is rather slow, see issue #674 for some comparisons. This is caused by its use ofjson.Marshal
andjson.Unmarshal
as a way of converting interfaces tomap[string]interface{}
in theconvertMap
method.This PR replaces the JSON logic with a custom, reflection based converter instead.
It also adds a benchmark to measure the performance impact.
Before the changes:
After the changes:
Roughly a 10x speedup. There might be some edge-cases I have missed, but looks like
convertMap
conforms to the behavior of its previous version.Fixes #674