-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improves import times by delaying imports when needed #13281
Improves import times by delaying imports when needed #13281
Conversation
👷 Deploy request for prefect-docs-preview pending review.Visit the deploys page to approve it
|
if TYPE_CHECKING: | ||
from prefect.client.schemas.schedules import SCHEDULE_TYPES |
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.
@bunchesofdonald Are you able to comment on why this one is currently prefect.server
? It seemed to be backwards compatibility for build_from_flow
based on the PR I saw, but wanted to double check on it
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.
Yeah, essentially. Since we're doing an isinstance
check we need to check against the server's version for that to work out, the client's version isn't the same instance. Having this behind a TYPE_CHECKING
flag should be fine.
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.
Okay, cool, what I'm hearing is that we should then probably do:
if TYPE_CHECKING:
from prefect.server.schemas.schedules import SCHEDULE_TYPES
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.
Hello!
Currently (Before this PR), we have:
from prefect.client.schemas.schedules import SCHEDULE_TYPES
SERVER_SCHEDULE_TYPES
(prefect.server.schemas.schedules) is only used to raise an error.
Why would we want to replace this line with the server version?
Is the current code no good?
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.
@bsignoret Ah, no that's not what I meant, I meant in addition to that, but looking further, keeping it behind TYPE_CHECKING
won't work anyway.
However, I think we could simplify this with reflecting type checking like so:
is_server_schema = obj.__class__.__module__ == "prefect.server.schemas.schedules"
if is_server_schema:
raise ValueError(
"Server schema schedules are not supported. Please use "
"the schedule objects from `prefect.client.schemas.schedules`"
)
Then we can avoid importing any server-side schema. Would you be willing to give that a shot? Tests passed for me locally with that 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.
Thank you for your idea. I've just made the modification and tests are also passed on my side.
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.
Nice! I'm running our workflows again, and if they pass, I think to future-proof against schedule
module name changes and to make it more generic, we probably want to change this last line:
return obj.__class__.__module__.startswith("prefect.server.schemas")
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.
Sorry, hope you don't mind but I'd love to get this in for Thursday's release, so I made this change in cc8dde8
Hi @bsignoret, thanks for opening your first PR(s) with Prefect! Appreciate these improvements, we were currently working on that this week so it's great timing. You can fix the failing tests in at lines 259 and 334. Additionally, I think you'll need to actually import the client side schedule type schema in the I pulled your branch and confirmed that the failing tests pass with those changes, so provided you get a chance to make those changes we can run the workflows here again and see if there's anything else left to fix to get this through! |
Thanks for your feedback! However, I'm not sure I understand this modification:
|
Hi @bsignoret, after chatting with @bunchesofdonald I think that we want to still keep the server schema but put it behind the |
src/prefect/runner/runner.py
Outdated
from prefect.runner.server import start_webserver | ||
|
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 think moving this here may be causing the failing tests but haven't checked
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.
Hope you don't mind, I'd love to get this in so I'm fixing these failing tests
b0f9fbe
to
cc8dde8
Compare
161190c
to
f9cee3f
Compare
Update:
In order to resolve these, I put up a PR to defer an import that was importing, among other things, Defer import of As well as a PR to Lazily instantiate |
92cca03
into
PrefectHQ:all-about-that-infra-base
This reverts commit 92cca03.
This reverts commit 92cca03.
In some places, imports can be moved for faster loading times.
Example
On my computer, here's the result (it's not a precise measurement):
python -X importtime -c "from prefect import Runner"
before:
after:
Checklist
<link to issue>
"maintenance
,fix
,feature
,enhancement
,docs
.For documentation changes:
netlify.toml
for files that are removed or renamed.For new functions or classes in the Python SDK:
mkdocs.yml
navigation.