question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selector use case: optimize rendering of pure/surjective functions

See original GitHub issue

The issue I often deal with involves “surjective” functions for deriving state (from other state slices). That is to say, several different inputs might output the exact same state. I want to avoid re-rendering in that circumstance. Clearly the computation must occur, but for instance, not every useEffect dependency change necessarily changes state.

Managing the sequential dependency, where one slice is a computationally complex derivation from another, And requires the end-user to review and further “configure” the computed state, while still having the ability to “backtrack” in order to change the inputs, is something I suspect recoil might help with.

Thank you in advance for clarifying how the library might support this use case.

- E

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
drarmstrcommented, Sep 4, 2020

What gets in the way of making that assumption?

Even with completely pure functions, we can’t say anything about uniqueness of results. f(0) -> 'a' and f(1) -> 'a' So, #314 should control propagation of updates based on the actual result of selector evaluation. In addition, simple reference equality is not always appropriate; we would want to allow for some user-defined value-equality check.

Redundant calculations for equivalent inputs are already limited based on selector caching. The current policy is based on reference equality. Internally we use different policies now, but that should not be necessary with #314

I know I would love to avoid calculations based on the input. An alternative that makes this less of an issue would be if #317 is implemented, as each map, bind, etc would be a separate selector and halt processing after getting a known output.

Limiting propagation of updates would be really awesome with a functional atom map() in #317. Though, it is still fun and useful without that. We actually have implemented it already in #319. However, we don’t want to merge it yet because it encourages risky usage of mapping during a render function. Without memoizing the map function this would lead to a new selector with every render. We tossed around some ideas, but currently thinking of just adding a simple lint rule to protect against this.

I’m going to close this issue now as a duplicate of #314, but please clarify if you see a specific example use-case that wouldn’t be covered by that approach.

0reactions
Shmewcommented, Sep 3, 2020

@edmundsecho

What gets in the way of making that assumption?

Impurity, I’d imagine.

I know I would love to avoid calculations based on the input. An alternative that makes this less of an issue would be if #317 is implemented, as each map, bind, etc would be a separate selector and halt processing after getting a known output. However, it would encourage splitting what would normally be an acceptable function into more pieces to avoid further computations.

Meaning instead of myAtom.map(x => (x + 5) * 2) it may encourage myAtom.map(x => x + 5).map(x => x * 2). I don’t know if the number of selectors becomes an issue with splitting things up like that though, so it’s possible that’s a non-issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LNCS 2967 - Generic Model Management - Springer Link
model management system, introduce the algebraic operators that are used ... 2.4 using selector ... Mapping map is a surjective function onto m...
Read more >
Isabelle
This volume is a self-contained introduction to interactive proof in higher- order logic (HOL), using the proof assistant Isabelle.
Read more >
The role of linearity in sharing analysis
Linearity plays a key role in sharing analysis, since it allows us to propagate precise sharing information when dealing with method calls.
Read more >
Untitled
Frederick md used auto parts, Tsm new jungler reddit, Harga printer brother 6710, Colors salon ... Descargar skin selector cleo 3, Blackbear 4u...
Read more >
Maple 7 Programming Guide
9.2 Programming with Plotting Library Functions . . . . . . 421 ... Maple echoes the result—in this case an exact rational...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found