Optimize Effect.map with dedicated OP_MAP opcode (inspired by ZIO's Mapped) #6024
civilizeddev
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Effect team! 👋
I'd like to propose a performance optimization for
Effect.mapinspired by recent work in the ZIO.🔍 Current Situation
Currently,
Effect.mapis implemented as:This involves 3 dispatch cycles and intermediate allocations for each map operation.
💡 Proposed Idea
Add a dedicated
OP_MAPopcode with continuation chaining, similar to ZIO'sMappedoperation.Background: My colleague originally proposed this optimization for zio-prelude (PR #1607), and ZIO maintainers recently adopted this idea for ZIO core (PR #10405).
The key optimization is to apply continuation chaining (similar to
OP_SYNC) to directly call the next continuation instead of returning a new primitive, reducing dispatch cycles from 3 to 2.📊 Preliminary Results
I've implemented a prototype and ran some benchmarks:
All existing functionality tests pass (error handling, Effect.gen integration, etc.).
💭 Thoughts
To be honest, I don't have deep knowledge of Effect's internals - just coded up a prototype based on vibes and following the
OP_SYNCpattern. If you're curious to take a look, I'm happy to open a draft PR!Let me know if this is worth exploring further 🙂
Beta Was this translation helpful? Give feedback.
All reactions