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

perf: Cache register plugin function #18860

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions py-polars/polars/plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import contextlib
from functools import lru_cache
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable

Expand Down Expand Up @@ -111,6 +112,7 @@ def _serialize_kwargs(kwargs: dict[str, Any] | None) -> bytes:
return pickle.dumps(kwargs, protocol=5)


@lru_cache(maxsize=16)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

a large number of pathlib objects can be heavy to cache: psf/black#1950. so i think it's good to set a maxsize

I think it's very unlikely that anyone would be using more than 16 plugins in the same project anyway..

Copy link
Member

Choose a reason for hiding this comment

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

Not in a hot loop at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

a large number of pathlib objects can be heavy to cache: psf/black#1950. so i think it's good to set a maxsize

I think it's very unlikely that anyone would be using more than 16 plugins in the same project anyway..

Does 16 mean 16 different plugin functions or 16 distinct plugins?

Copy link
Contributor

Choose a reason for hiding this comment

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

NVM, should be 16 plugin packages..

def _resolve_plugin_path(path: Path | str) -> Path:
"""Get the file path of the dynamic library file."""
if not isinstance(path, Path):
Expand Down