-
Notifications
You must be signed in to change notification settings - Fork 292
use default allocator #662
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
Conversation
CodSpeed Performance ReportMerging #662 Summary
Benchmarks breakdown
|
In my opinion, reliable benchmarks, more consistent performance, and saving developer time chasing down weirdness (see #656 (comment) for context) are well worth a mean 15% performance regression on micro benchmarks. There is also the option of using the default allocator only for benchmarks but keeping MiMalloc for the prod builds which technically might give us the best of both worlds but has the con that benchmark performance would not be reflective of real-world performance (although I think a 10-25% variation between them would be fine as long as it's relatively consistent). @samuelcolvin what do you think? |
7325d42
to
dbdf001
Compare
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #662 +/- ##
=======================================
Coverage 93.90% 93.90%
=======================================
Files 99 99
Lines 13756 13756
Branches 25 25
=======================================
Hits 12917 12917
Misses 833 833
Partials 6 6
Continue to review full report in Codecov by Sentry.
|
- name: Install pydantic-core | ||
# build-prod does not include MiMalloc because it bypasses Maturin | ||
run: | | ||
make build-prod |
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 thought about it more and realized I think the make build-dev
thing doesn't work for me locally if it isn't already pip installed in editable mode. (Which is often an issue for me because I switch between released version and locally installed versions sometimes.) Maybe try:
make build-prod | |
pip install -e . | |
make build-prod |
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.
How will we know which version is installed then 🥲
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.
Similarly, I guess we need to confirm that the MiMalloc version is what wheels are using
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.
Not sure if it's worth it, but I would imagine you could add an attribute to the pydantic_core._pydantic_core
module conditionally based on the mimalloc feature flag? (And then check for it when uploading the wheel if necessary?)
diff --git a/pydantic_core/_pydantic_core.pyi b/pydantic_core/_pydantic_core.pyi
index 6859a16..517d507 100644
--- a/pydantic_core/_pydantic_core.pyi
+++ b/pydantic_core/_pydantic_core.pyi
@@ -21,6 +21,7 @@ from _typeshed import SupportsAllComparisons
__all__ = (
'__version__',
+ 'allocator',
'build_profile',
'SchemaValidator',
'SchemaSerializer',
@@ -35,6 +36,7 @@ __all__ = (
'list_all_errors',
)
__version__: str
+allocator: str
build_profile: str
T = TypeVar('T', default=Any, covariant=True)
@@ -167,7 +169,8 @@ class Url(SupportsAllComparisons):
def query(self) -> 'str | None': ...
@property
def fragment(self) -> 'str | None': ...
- def __init__(self, url: str) -> None: ...
+ @staticmethod
+ def __new__(cls, url: str) -> Url: ...
def unicode_host(self) -> 'str | None': ...
def query_params(self) -> 'list[tuple[str, str]]': ...
def unicode_string(self) -> str: ...
diff --git a/src/lib.rs b/src/lib.rs
index 613220a..9e9229e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,9 +42,20 @@ pub fn get_version() -> String {
version.replace("-alpha", "a").replace("-beta", "b")
}
+#[cfg(feature = "mimalloc")]
+fn get_allocator() -> String {
+ "mimalloc".to_owned()
+}
+
+#[cfg(not(feature = "mimalloc"))]
+fn get_allocator() -> String {
+ "default".to_owned()
+}
+
#[pymodule]
fn _pydantic_core(_py: Python, m: &PyModule) -> PyResult<()> {
m.add("__version__", get_version())?;
+ m.add("allocator", get_allocator())?;
m.add("build_profile", env!("PROFILE"))?;
m.add_class::<PySome>()?;
m.add_class::<SchemaValidator>()?;
(Haven't tested; also maybe it's overkill)
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.
Looks like it’s using the default allocator for benchmarks now based just on the slowdowns 😂.
I was thinking something similar but it’s complex. How do you feel about moving forward without that and add ing it later if it’s really needed?
Co-authored-by: David Montague <[email protected]>
@samuelcolvin I'll merge this now since @adriangb and I agree it's good and it sounded earlier like you were okay with this, but just comment if you want more work done or whatever Edit: oh looks like @adriangb beat me |
No description provided.