https://kotlinlang.org logo
#http4k
Title
# http4k
r

Razi Kheir

10/16/2019, 8:19 AM
I was wondering something regarding lenses. Should I define a lens such as this:
Copy code
Body.auto<RequestBody>().toLens()
Once as a constant and use it inside of other methods? Or write it inside of a method? I guess what i’m asking if it will be recreated every time in the method with no reason :x
1
d

dave

10/16/2019, 8:21 AM
You can do either - we tend to (inconsistently) define them as constants so they can be reused easily - but TBH I suspect that recreating them every time would have a negligible effect in the grand scheme of things
👍 1
r

Razi Kheir

10/16/2019, 8:46 AM
I’m a bit anal about performance 😄
d

dave

10/16/2019, 8:46 AM
then measure it and let us know! 😉
1
but yes - sharing the instance is our preferred mechanic
and also, the JVM is really good at optimising hot code paths, so you might find that it makes less difference over time
👍 1
r

Razi Kheir

10/21/2019, 5:56 AM
Sorry dave, I’m so swamped at work I don’t even have time to run these tests, but once things calm down I’ll be using http4k in my personal project and bench mark it and share 😄
👍 1
4 Views