Skip to content
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

Merged
merged 9 commits into from
Sep 13, 2024
Merged

docs: use_memo docs #779

merged 9 commits into from
Sep 13, 2024

Conversation

mofojed
Copy link
Member

@mofojed mofojed commented Aug 28, 2024

  • 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
@mofojed mofojed self-assigned this Aug 28, 2024
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should explicitly mention queries.

plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Outdated Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Show resolved Hide resolved
margaretkennedy and others added 3 commits August 30, 2024 09:57
- Added a `time_table` example with memoization
- Other misc cleanup
@mofojed mofojed requested a review from dsmmcken September 3, 2024 20:04
- Add details about looping
plugins/ui/docs/hooks/use_memo.md Show resolved Hide resolved
plugins/ui/docs/hooks/use_memo.md Show resolved Hide resolved
`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
Copy link
Contributor

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?

Copy link
Member Author

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?

@@ -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.
Copy link
Contributor

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?)?

Copy link
Member Author

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.

@mofojed mofojed requested a review from dsmmcken September 6, 2024 14:02
dsmmcken
dsmmcken previously approved these changes Sep 9, 2024
Copy link
Contributor

@dsmmcken dsmmcken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs conflicts resolved.

margaretkennedy
margaretkennedy previously approved these changes Sep 9, 2024
dsmmcken
dsmmcken previously approved these changes Sep 13, 2024
Adding one comma and removing one extra space.
@mofojed mofojed merged commit abf4b72 into deephaven:main Sep 13, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui.use_memo docs
3 participants