Skip to content

Optimize liftOutcome in KleisliGenSpawn to avoid allocation#4598

Open
nmichael44 wants to merge 1 commit intotypelevel:series/3.xfrom
nmichael44:AvoidAllocationOfNaturalTransformationWhenUnnecessary
Open

Optimize liftOutcome in KleisliGenSpawn to avoid allocation#4598
nmichael44 wants to merge 1 commit intotypelevel:series/3.xfrom
nmichael44:AvoidAllocationOfNaturalTransformationWhenUnnecessary

Conversation

@nmichael44
Copy link
Copy Markdown
Contributor

Calling bothOutcome or racePair on a Kleisli evaluates liftOutcome,
which currently instantiates a new FunctionK and routes it through mapK.

This commit replaces the mapK invocation with a direct pattern match
on the Outcome. This optimization:

  1. Eliminates the FunctionK allocation on every invocation.
  2. Bypasses the evaluation overhead of mapK.
  3. Aligns the Kleisli implementation with OptionT, EitherT, IorT,
    and WriterT in GenSpawn.scala, which already use this exact
    pattern-matching technique.

…he mapK invocation with a direct pattern match on Outcome. This avoids allocating a new FunctionK on every invocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant