cloudwan / gohan

Gohan is an API Gateway Server written by Go that makes it easy for developers to create and maintain REST-style API
http://www.slideshare.net/natiueno/gohan-61170476
Other
109 stars 44 forks source link

Take advantage of reflectx.Mapper's internal cache. #721

Closed cierpuchaw closed 5 years ago

cierpuchaw commented 5 years ago

Building a StructMap is an expensive operation but fortunately there is a cache for that inside reflectx's Mapper struct. Unfortunately we were not using it because for every ResourceToMap call we created a new mapper instance. This commit changes that to always use one global mapper instance.

It's hard to measure exact performance improvements for ResourceToMap run times, because they vary depending on how complex input objects were. We might say that it is now a couple of times faster. What's more, our project based on gohan, sees 20% runtime improvement when running all tests, just because this one function is heavily used there.

Removed unused Clone method while at it.