Skip to content

[Presence] Improve Presence perf #465

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

Merged
merged 2 commits into from
Feb 22, 2021
Merged

[Presence] Improve Presence perf #465

merged 2 commits into from
Feb 22, 2021

Conversation

jjenzz
Copy link
Contributor

@jjenzz jjenzz commented Feb 20, 2021


ℹ️  Easier to review with hidden whitespace changes.


We had report of some perf issues with nested Collapsibles and I realised Presence was causing some problems there.

I've prevented some useEffect logic from running unnecessarily on mount and removed @xstate/fsm.

I had noticed that @xstate/fsm really eagerly re-renders components during my Carousel work so we can probably do without that and the additional bundle size it adds for such a simple machine here.

These changes managed to double the speed in my tests.

Comment on lines +12 to +19
export function useStateMachine<M>(
initialState: MachineState<M>,
machine: M & Machine<MachineState<M>>
) {
return React.useReducer((state: MachineState<M>, event: MachineEvent<M>): MachineState<M> => {
const nextState = (machine[state] as any)[event];
return nextState ?? state;
}, initialState);
Copy link
Contributor

Choose a reason for hiding this comment

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

♥️ how minimal this is haha, so good 🙂

};
}, [machine]);
// 🤯 https://fettblog.eu/typescript-union-to-intersection/
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm gonna still need some time to process this but I'll just do on my own time. I've played with it and it works very well! 👍

@jjenzz jjenzz merged commit 07ca41a into main Feb 22, 2021
@jjenzz jjenzz deleted the presence-perf branch February 22, 2021 14:34
benoitgrelard added a commit that referenced this pull request Mar 3, 2021
# New features

Breaking changes are indicated with a 🔥 icon.

- Add support for SSR
- [Accordion] Support multiple values (#527) 🔥
- [Tabs] Add RTL support (`dir` prop) (#497)
- Remove `selector` prop and `data-radix-*` atributes 🔥

# Fixes

- [Slider] Fix step rounding issue (#463)
- [Presence] Improve `Presence` perf (#465)
- Fixed potential issue with overriding attributes in certain primitives

# Maintenance

- Improved internal context handling
- Better package/dependency split
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.

2 participants