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

Lazy import modules in reflex #2144

Merged
merged 12 commits into from Nov 14, 2023
Merged

Lazy import modules in reflex #2144

merged 12 commits into from Nov 14, 2023

Conversation

picklelo
Copy link
Contributor

@picklelo picklelo commented Nov 7, 2023

This PR is intended to speed up the time to run import reflex. Before we were loading everything eagerly, and it could take several seconds simply to import the package. We now offload the importing until the actual field is called, speeding up import times.

On my MacBook Pro M1: import reflex as rx
Before:
Time (mean ± σ): 2.230 s ± 0.418 s [User: 2.416 s, System: 1.922 s]
Range (min … max): 2.061 s … 3.417 s 10 runs

After:
Time (mean ± σ): 395.3 ms ± 46.2 ms [User: 272.1 ms, System: 69.7 ms]
Range (min … max): 370.5 ms … 525.2 ms

@picklelo
Copy link
Contributor Author

picklelo commented Nov 7, 2023

This still needs to work with .pyi before merging. Maybe we can generate one for the base reflex/__init__.py

masenf
masenf previously approved these changes Nov 8, 2023
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

brilliant

picklelo and others added 4 commits November 9, 2023 15:17
Instead remove all deep reflex imports, and just eager import reflex.page,
since it is a simple module.
@picklelo picklelo merged commit 33e4816 into main Nov 14, 2023
45 checks passed
Alek99 pushed a commit that referenced this pull request Nov 20, 2023
@masenf masenf deleted the nikhil/lazy branch December 6, 2023 22:19
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.

None yet

3 participants