Skip to content

Commit a618d68

Browse files
committed
Documented modifyNow.
1 parent d4ef71f commit a618d68

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

docs/tutorials/range_rendering.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ auto foo() {
6363
std::transform(proxy->begin(), proxy->end(), proxy->begin(), [](int elem){
6464
return elem * 2;
6565
});
66+
67+
// You can also work directly on the value and call modify later:
68+
auto& value = numbers.value();
69+
std::transform(value.begin(), value.end(), value.begin(), [](int elem){
70+
return elem * 2;
71+
});
72+
73+
// modifyNow also calls the eventContext executeActiveEventsImmendiately.
74+
// This is not necessary from event attributes, because its called at the end anyway.
75+
numbers.modifyNow();
6676
}
6777
}()
6878
);
@@ -122,4 +132,16 @@ auto foo() {
122132
}
123133
)
124134
}
125-
```
135+
```
136+
137+
## Notes about the Optimization
138+
The ranges optimization that is applied to Observed<std::vector> and Observed<std::deque> makes it so that only the changed/inserted elements are rerendered and only erased elements are removed and nothing else is rerendered.
139+
This is done by tracking the changes using some algorithms on an interval tree.
140+
141+
Insertions, modifications and erasures are only ever tracked alone, so if you switch from inserting elements to modifying elements a rerender is forced.
142+
If you erase something after modifying, all erased elements that were previously modified will not be rerendered only if the erasure happens at the end.
143+
If you erase something after inserting, all erased elements that were previously inserted will not be rerendered only if the erasure happens at the end.
144+
145+
All wisdoms about modifying a vector apply to these optimizations. It is optimal to only ever add or erase from the end of the vector.
146+
The most detrimental thing you can do is inserting at every odd position or erasing at every odd position, this will defeat the optimization and it will
147+
be much better to just rerender the entire range.

0 commit comments

Comments
 (0)