kenbot / goggles

Pleasant, yet principled Scala optics DSL
MIT License
195 stars 7 forks source link

Can named lenses be inlined for performance? #30

Open kenbot opened 7 years ago

kenbot commented 7 years ago

@julien-truffaut mentioned that:

Lenses still cause a performance overhead around 2x comparing to hand written copy (as measured with jmh)

Since Goggles is generating code anyway, could we gain a speedup by directly generating the underlying code for chains of .name optics?

Getters would fuse into a single Getter with direct method calls: foo.bar.baz Setters would fuse into nested copy calls: foo.copy(bar = foo.bar.copy(baz = <new thing>)) Lenses could fuse both. (Don't forget that lens mode might produce Isos as well, pending #26!)

We would have to examine the produced bytecode to ensure parsimony, and we would have to introduce benchmarks to demonstrate that sufficiently impressive speedups occur in practice.

Since we would still want to provide the illusion of the segments being separate optics (ie in the fancy error message table), some clever software engineering might be required to maintain a modular design within the macro code.

julien-truffaut commented 7 years ago

potentially we could make this improvement in GenLens

kenbot commented 7 years ago

Good call! There will probably be a few things I can donate back to Monocle from the .name syntax stuff...