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

Performance of wrapper #1792

Closed
Saelyos opened this issue May 31, 2023 · 5 comments · Fixed by #1866
Closed

Performance of wrapper #1792

Saelyos opened this issue May 31, 2023 · 5 comments · Fixed by #1866

Comments

@Saelyos
Copy link
Contributor

Saelyos commented May 31, 2023

I'm using pint in my library with some wrappers that give a nice user interface, but unfortunately they also take a lot of time.
Basically I'm using a code that looks like this:

from pint import UnitRegistry

ureg = UnitRegistry()


class Foo:
    def __init__(self, q):
        self.q = q

    @property
    @ureg.wraps("meter", (None,))
    def q(self) -> ureg.Quantity:
        return self._q

    @q.setter
    @ureg.wraps(None, (None, "meter"), strict=False)
    def q(self, value: float) -> None:
        self._q = value

I'm then using self._q (without unit) for some relatively heavy computations.

Unfortunately most of the time is spent in the object creations . This is particularly frustrating with strict=False, when even calling Foo(100) takes a lot of time, as one could expect a more transparent process.

Yet I'm not sure if anything can be done to speed up the process. In case it can help, I've attached the profiler results from my application showing the time spend in pint:

image

@matroscoe
Copy link

I have also been running into significant performance bottle necks as documented in: #1750

@hgrecco
Copy link
Owner

hgrecco commented Jun 1, 2023

Performance will be address in the next version. Would you like to help developing or improving the benchmark?

@Saelyos
Copy link
Contributor Author

Saelyos commented Jun 2, 2023

I'm not sure how much time I'll be able to spend on this, but I'll try to help improving the performances

@hgrecco
Copy link
Owner

hgrecco commented Jul 14, 2023

I pushed some benchmarks. The results are : https://codspeed.io/hgrecco/pint/benchmarks

There are still things to polish, but is a good start.

@hgrecco
Copy link
Owner

hgrecco commented Jul 16, 2023

See #1820

@Saelyos Saelyos mentioned this issue Jul 20, 2023
5 tasks
This was referenced Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants