Exerosis
12/17/2021, 8:30 PMDominaezzz
12/17/2021, 8:57 PM+
operator tbh. Depends on the type but I doubt it's been optimised away.Rob Elliot
12/17/2021, 9:12 PMExerosis
12/17/2021, 9:21 PMjimn
12/18/2021, 2:08 PMif(x in container1||x in container2 )
is not a bad hedge. creating a tiny array of two containers and testing them by size first is reasonably elligable for EA without additional memory speculation costjimn
12/18/2021, 2:13 PMYoussef Shoaib [MOD]
12/20/2021, 4:23 PMplus
for collections is inline, and so probably what's missing is to optimize the case where a collection is created out of multiple others only for a single check.
However, what would be even better, instead of relying on little optimizations in the compiler, is if we took a page out of fp land and went with a lazy approach here. If those 2 containers were added together into a sequence in a lazy fashion, then that sequence would implement its methods to also reflect that. For example, for a special PlusSequence
, it can implement its contains
method to check the 2 containers inside of it. The only issue with this solution is the creation of the extra Sequence object, which isn't ideal because it kind of takes away the value of the optimization. However, with Valhala value classes, or KT-44530, this new sequence can just be inlined and would never have to exist as an object in memory. I had been developing a compiler plugin that can acomplish that, and I'm gonna resume development soon.