-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: use_memo docs #779
docs: use_memo docs #779
Conversation
mofojed
commented
Aug 28, 2024
•
edited
Loading
edited
- Add docs for use_memo
- Give some examples of using memoization, and recommendations of when to use it and when not to use it
- Fixes ui.use_memo docs #728
- Add docs for use_memo - Give some examples of using memoization, and recommendations of when to use it and when not to use it
1. **Use memoization for expensive computations**: If you have a value that is expensive to compute, use `use_memo` to memoize the value between renders. | ||
2. **Use dependencies**: Pass in only the dependencies that the memoized value relies on. If any of the dependencies change, the memoized value is re-computed. If another prop or state value changes, the computation is not re-run. | ||
3. **Do not use for cheap computations**: There is small overhead to memoizing values, so only use `use_memo` for expensive computations. If the value is cheap to compute, it is not worth memoizing. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should explicitly mention queries.
Co-authored-by: Don <[email protected]>
- Added a `time_table` example with memoization - Other misc cleanup
- Add details about looping
`use_memo` can be used to memoize table operations. In the example below, we have a slider to adjust an integer value, a ticking table that will add a new row every second with the new result, and our theme picker from the previous example: | ||
|
||
```python | ||
from deephaven import time_table, ui |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if a more real example would work better of when I should an shouldn't memoize a query.
Also time tables will suck to auto generate screenshots.
Like _stocks
and memoize the rollup but not a filter?
with an option to selct rollup on sym or exchange and filter free-form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with rollups and filters is that they are both memoized by the engine, so it doesn't really demonstrate why you need to memoize (since it's already memoized).
_stocks
would have same issue as time_table
for screenshots?
plugins/ui/docs/hooks/use_memo.md
Outdated
@@ -1,6 +1,6 @@ | |||
# use_memo | |||
|
|||
`use_memo` is a hook to memoize a value. This is useful when you have a value that is expensive to compute, and you want to avoid re-computing it on every render. The value is computed once, and then stored in the memoized value. The memoized value is returned on subsequent renders until the dependencies change. | |||
`use_memo` is a hook to cache the result of a calculation. This is useful when you have a value that is expensive to compute and you want to avoid re-computing it on every render. The value is computed once and then stored in the memoized value. The memoized value is returned on subsequent renders until the dependencies change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is calculation the right word? The result of a calculation, function or table reference (handle?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Straight from the react.dev docs: https://react.dev/reference/react/useMemo
I could add some synonyms there.
Co-authored-by: Don <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs conflicts resolved.
6eff906
Adding one comma and removing one extra space.