Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Make memoization compatible with MPP #331

Merged
merged 16 commits into from Feb 18, 2021
Merged

Conversation

aballano
Copy link
Member

@aballano aballano commented Feb 8, 2021

Replace ConcurrentHashMap impl by atomic to be able to work in MPP

@aballano aballano requested a review from a team February 8, 2021 14:58
Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👌 Thanks @aballano!

* ```
*
* Note that calling this function with the same parameters in parallel might cause the function to be executed twice.
*/
fun <R> (() -> R).memoize(): () -> R = object : () -> R {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to define them as suspended functions. Given the nature of memoizing, or am I mistaken here?
cc @nomisRev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR just updates the existing code to remove the dependency on Java classes. We can do a variant of this for suspending code as well.
Kinda silly that this needs to be defined separately tho, since normal code should work for suspending code. Only the other way around is not true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the suspend version is the only pure/referential transparent implementation since it involves allocation mutable shared state to do the memoisation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was one of my concerns.
Maybe it's worth deprecating it first and rolling out a suspended version either here or in Arrow Fx

@aballano
Copy link
Member Author

@rachelcarmena @nomisRev Seems this PR is failing for arrow-fx due to test flakiness(?) or might have my changes affected that?

@nomisRev
Copy link
Member

@aballano seems to be the case of something flaky in Arrow Fx and Arrow Fx RxJava which are both deprecated so not very concerning but I've never seen the flaky test in Arrow Fx RxJava.

I restarted the build. Have you seen this multiple times on this PR?

@aballano
Copy link
Member Author

@nomisRev Yes, the previous build after merging master also failed due to failed test for Bracket in the stream package

@aballano aballano requested a review from a team February 16, 2021 16:26
Copy link
Member

@i-walker i-walker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aballano 🙌

@aballano aballano merged commit 77f8d71 into master Feb 18, 2021
@aballano aballano deleted the ab/make-memoization-mpp branch February 18, 2021 09:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants