Currently the EP code clones an entry if there is an index. See:
https://github.com/hazelcast/hazelcast/blob/c5e1652fc82070f470ac232f432ef93cfb993a30/hazelcast/src/main/java/com/hazelcast/map/impl/MapContainer.java#L349-L351
An optimisation would be either skipping cloning if the EP is marked with com.hazelcast.core.ReadOnly or extracting all index values instead of cloning the object.
Probably an issue with extracting the index values would be that the index values themselves could be objects which could be mutated inside the EP. If keeping these values is only needed to remove the correct index entry, maybe we could have some other way of referring to an index entry so it can be removed after the EP.
Just quick comment for now: the issue is, that we do not trust the user not to modify the object. That is the reason why we create the cloned version even if the EP is ReadOnly.
We would need clear conventions for this. I would tend to move it to 4.0, since it could be a breaking change, even if we decided to use this Immutable (since this annotation has no practical meaning).
I agree this could be optimised. With index we would need some further improvements
While I agree you should not trust users :) I see no point in ReadOnly thing then. If people cannot tell you that their EP is "safe" (or if they tell you but you do not believe them) - what is the point of that information?
Also, I would like to ask you that whatever optimisation you come up with, please do not make it a special optimisation for ReadOnly case. Serialising an entry before each EP invocation is a serious hit for the whole EP industry so to say. It completely defeats the purpose of OBJECT memory format which docs say is good specifically for these cases.
We changed format to OBJECT because we believed we getting rid of these serialisations in the first place (the vast majority of our operations are mutations applied with EPs).
By the way, where that cloned value is actually used? I dug through EntryOperator and cannot find any use of it. It is kinda used in publishEntryEvent() but for OBJECT format it actually gets replaced with null unless entry was removed. The only other way this value can be exposed I see is getOldValue() getter but I cannot find what uses it.
Cheers
While not trusting the users is sensible default, it would be nice if there existed a way to configure the map to skip cloning. In performance sensitive setup that can provide quite a tangible boost.
Most helpful comment
While not trusting the users is sensible default, it would be nice if there existed a way to configure the map to skip cloning. In performance sensitive setup that can provide quite a tangible boost.