-
Notifications
You must be signed in to change notification settings - Fork 997
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
use process pool to compile faster #2377
Conversation
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.
awesome it's actually faster
need to merge main
to get it working with the latest reflex-web radix changes
reflex/app.py
Outdated
@@ -82,6 +84,118 @@ def default_overlay_component() -> Component: | |||
return connection_modal() | |||
|
|||
|
|||
class ExecutorSafeFunctions: |
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.
feels like this class belongs in reflex/compiler/utils.py
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.
Good idea. IMO the gymnastics involved are little icky so encapsulating as much as we can would be good. More to do in future on that front.
reflex/app.py
Outdated
@staticmethod | ||
def compile_page(route: str): | ||
"""Compile a page. | ||
|
||
Args: | ||
route: The route of the page to compile. | ||
|
||
Returns: | ||
The path and code of the compiled page. | ||
""" | ||
return compiler.compile_page( | ||
*ExecutorSafeFunctions.COMPILE_PAGE_ARGS_BY_ROUTE[route] | ||
) |
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 there a particular reason to go for the staticmethod
over classmethod
when these do in fact access members of the class?
seems like that would have less code duplication and make it easier to subclass/monkeypatch if some behavior modifications were needed downstream.
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.
No particular reason. These things started out as full global vars or functions, in fact! The key property is only that the forked child process is able to get at the data / functions correctly. I can try to see if @classmethod
works as well.
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.
cool!
* Revert "Revert "Revert "Revert "use process pool to compile faster (#2377)" (#2434)" (#2497)" (#2595)" This reverts commit 6b6eea4. * Adjust number of operations for more correct progress bar * app: recognize REFLEX_COMPILE_PROCESSES and REFLEX_COMPILE_THREADS Control whether multiprocessing is used and the number of processes or threads that should be used. This will allow users to opt-in to the new, potentially hazardous, multiprocessing mode, which results in much faster compiles, but has already been reverted 4 times. Lets leave the code in this time, but use the thread pool executor by default. Limiting the number of threads or processes to 1 can also aid in debugging issues that arise during compile time. * Allow REFLEX_COMPILE_PROCESSES=0 to trigger multiprocessing with auto workers
We also do some general cleanup - for steps that are not being parallelized, it should run outside of the executor context manager.
As an aside, we stop using multi-threading to write out final compilation output to file system. Even for a large project like reflex-web, that part takes about 200ms on my laptop (Macs are fancy, but pretty much everyone has SSDs).
Before (reflex-web):
![image](https://private-user-images.githubusercontent.com/136611113/295377140-6bbf6476-6b97-47e8-8433-ed7b8c0b7a08.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2MDI3NDcsIm5iZiI6MTcyMDYwMjQ0NywicGF0aCI6Ii8xMzY2MTExMTMvMjk1Mzc3MTQwLTZiYmY2NDc2LTZiOTctNDdlOC04NDMzLWVkN2I4YzBiN2EwOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxMFQwOTA3MjdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lYWNjMDM2MDM2ZTMxNTE2NGNhMzAyZDkxMDNiOTNhMzQzNjRhZjRhNjFhNmFmZDcyZGVmNmFiOGYxMzNlOWRjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rv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