-
Notifications
You must be signed in to change notification settings - Fork 81
Faster spatialdata import time
#1075
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
Open
LucaMarconato
wants to merge
6
commits into
main
Choose a base branch
from
faster-import
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63600ed
add profimp dev dep
LucaMarconato ed9f72f
made imports lazy
LucaMarconato bcbef43
more repeats for import benchmarks
LucaMarconato d3e4649
add profimp to optional requirements
LucaMarconato ce54b02
relax pre-commit ignore; cleanup optional deps
LucaMarconato 0dce65b
tests: force string annotations
flying-sheep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Benchmarks for import times of the spatialdata package and its submodules. | ||
|
|
||
| Each ``timeraw_*`` function returns a snippet of Python code that asv runs in | ||
| a fresh interpreter, so the measured time reflects a cold import with an empty | ||
| module cache. | ||
| """ | ||
|
|
||
| from collections.abc import Callable | ||
| from typing import Any | ||
|
|
||
|
|
||
| def _timeraw(func: Any) -> Any: | ||
| """Set asv benchmark attributes for a cold-import timeraw function.""" | ||
| func.repeat = 5 # number of independent subprocess measurements | ||
| func.number = 1 # must be 1: second import in same process hits module cache | ||
| return func | ||
|
|
||
|
|
||
| @_timeraw | ||
| def timeraw_import_spatialdata() -> str: | ||
| """Time a bare ``import spatialdata``.""" | ||
| return """ | ||
| import spatialdata | ||
| """ | ||
|
|
||
|
|
||
| @_timeraw | ||
| def timeraw_import_SpatialData() -> str: | ||
| """Time importing the top-level ``SpatialData`` class.""" | ||
| return """ | ||
| from spatialdata import SpatialData | ||
| """ | ||
|
|
||
|
|
||
| @_timeraw | ||
| def timeraw_import_read_zarr() -> str: | ||
| """Time importing ``read_zarr`` from the top-level namespace.""" | ||
| return """ | ||
| from spatialdata import read_zarr | ||
| """ | ||
|
|
||
|
|
||
| @_timeraw | ||
| def timeraw_import_models_elements() -> str: | ||
| """Time importing the main element model classes.""" | ||
| return """ | ||
| from spatialdata.models import Image2DModel, Labels2DModel, PointsModel, ShapesModel, TableModel | ||
| """ | ||
|
|
||
|
|
||
| @_timeraw | ||
| def timeraw_import_transformations() -> str: | ||
| """Time importing the ``spatialdata.transformations`` submodule.""" | ||
| return """ | ||
| from spatialdata.transformations import Affine, Scale, Translation, Sequence | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 added this. It makes it so the
UPlints will always flag when you’re just using an import in an annotation, and therefore will automatically skip such imports at runtime by sticking them intoif TYPE_CHECKING:blocks.