Open Bug 1637820 Opened 6 years ago Updated 3 months ago

Make mozbuild.util.memoize support memoizing functions with kwargs

Categories

(Firefox Build System :: General, enhancement, P5)

enhancement

Tracking

(Not tracked)

REOPENED

People

(Reporter: marco, Unassigned)

References

Details

(Keywords: good-first-bug)

Priority: -- → P5

Note that Python 3 has built-in memoization in the standard library, so augmenting the homebrewed memoize function is probably not a good use of time.

True, the only problem with the built-in lru_cache function is that it leaks memory when applied to a class method. So we'd need to be careful with it.

Severity: -- → S4

True, the only problem with the built-in lru_cache function is that it leaks memory when applied to a class method. So we'd need to be careful with it.

Ah, I'm guessing that that lru_cache problem is this python ticket here.
FWIW, this same downside applies to our homebrewed memoize function, too.

Since we're now running with Python 3.6+, we can lean on the built-in lru_cache to memoize kwargs functions.

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → WONTFIX

Should we keep this open to make memoize = functools.lru_cache(maxsize=None)? (3.9 has functools.cache but 3.9 is a long way)

Flags: needinfo?(mhentges)

I'm not sure that having our own alias is necessary.
However, I would be on-board with migrating existing mozbuild.util.memoize usages to instead use lru_cache.

Flags: needinfo?(mhentges)

The point of an alias is that functools.lru_cache is not very convenient replacement on its own. functools.cache would be.

Sure, that would work.

Status: RESOLVED → REOPENED
Resolution: WONTFIX → ---

So, is the hand-rolled memoize class in utils.py still in use? If we have moved on to the built-in in python3, perhaps the util.py version should be removed from the code, this bug closed, and a different bug logged for the suggested alias solution above?

Yeah, since 3.9 is our minimum supported version for a while now (soon to be 3.10) we should be able to replace this with the builtin functools.cache and functools.cached_property.

You need to log in before you can comment on or make changes to this bug.