Comments (3)
Interesting. I wonder if this should use referential equality or an Eq state
instance. It might cause a slowdown if it's a default implementation, but puts the burden on the developer to implement Eq
.
So I understand, in what cases does referential equality lead to a performance improvement? For most PS data types, ===
would rarely evaluate to true
in practice, right?
from purescript-thermite.
Edit: somehow managed to submit this while typing.
Just to be clear, it's not just ===
on the objects themselves, but also checking for reference equality on their field values as well. So in thermite, when properties are assembled into new property objects from the Props
list, it's true that the reference equality of the property objects will not hold, but it is possible that the reference equality of all their fields holds. Field equality is more likely to hold when the properties are passed in directly.
A couple cases I encountered while playing with purescript-signal
and virtual-dom
.
- Let's say you have a model that is processing a fast incoming event stream, like mouse position or drag events, and it's being rendered to a complicated GUI. The GUI can't render fast enough to keep up, so you decide to downsample using
sampleOn
to sample at, say, 50 ms. However,sampleOn
will fire an event every 50 ms whether the signal it's sampling changed or not. To get around this, I useddistinct'
in combination withsampleOn
. The result is a reference equality check every 50 ms, and only when reference equality fails does the GUI re-render. This puts an upper bound on GUI refresh rate. UsingshouldComponentUpdate
with reference equality is similar to usingdistinct'
in this example. - Your GUI displays info about the model state. Your model processes incoming messages to update state, but some cases results in no change to the state. In that case, returning the state unchanged to the GUI render function should satisfy reference equality, so the GUI doesn't need to update. This case is similar to 1) above if the messages are coming in at a high rate.
As for implementation, I think reference equality is the way to go. My aim here is not to eliminate all unnecessary GUI updates, but only to eliminate those that are easy to guard against in a convenient way. If the new props and state are the same as the old ones, or their field values are the same as the old values, then there is nothing to update.
Using Eq
instance, to me, is a little too far removed from the philosophy of "just rerender the GUI every update" because now the Eq
instance is essentially responsible for determining whether the GUI should redraw or not. Also, we don't want the props to need to be wrapped in newtypes in order to define typeclasses for them (at least I don't).
from purescript-thermite.
I think this should be implemented in purescript-react
, or another library.
from purescript-thermite.
Related Issues (20)
- Uprade to PS 0.12 ? HOT 6
- README: defaultMain params seem incorrect HOT 2
- What is R.p' in the Getting Started Documentation? HOT 2
- Thermite example doesnt seem to work HOT 1
- Can't run the example HOT 3
- Add subscriptions and initialAction
- Multiple 'update' actions work on initial copy HOT 3
- Can't get any examples working HOT 7
- Missing hello world / template? HOT 6
- Two state updates (cotransforms) in one performAction HOT 4
- Use of div' in render causes problems with react-native HOT 14
- Any plans to add JSX support!? HOT 1
- Asynchronous handlers closing over state? HOT 1
- Monolithic components HOT 1
- Routing and actions/effects while switching views HOT 2
- Server Side Rendering in Thermite HOT 5
- ReactDOM failed to load HOT 3
- example project demo link in README.md is broken HOT 1
- `createReactSpec` type too restrictive. HOT 4
- Remove DOM dependency HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-thermite.