perf: Make frappe._dict great again (#28824)

* perf: Restore dict's flat overrides

Using `super()` is unnecessary cost. This class is used A LOT. Ref: https://github.com/frappe/frappe/pull/16449/

Please consider performance while adding types, it's almost always possible to achieve good typing without this.

Also `frappe._dict` is almost always used as `dict[Any, Any]` or
`dict[str, Any]`, type annotations are useless here.

* ci: ugh wait for processes to exit
This commit is contained in:
Ankush Menat 2024-12-18 16:36:31 +05:30 committed by GitHub
parent 7dd15e3613
commit 004990e53e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 13 deletions

View file

@ -104,7 +104,7 @@ jobs:
if pgrep honcho > /dev/null; then
echo "Stopping honcho process..."
pgrep honcho | xargs kill
sleep 5
sleep 10
fi
echo "Setting up environment..."

View file

@ -16,19 +16,13 @@ class _dict(dict[_KT, _VT]):
__slots__ = ()
def __getattr__(self, k: str) -> _VT | None:
return super().get(k) # type: ignore[arg-type]
# NOTE(perf): Do NOT use super() here, it's an unnecessary function call!
# Refer: https://github.com/frappe/frappe/pull/16449
@override
def __setattr__(self, k: str, v: _VT) -> None:
return super().__setitem__(k, v) # type: ignore[index]
@override
def __delattr__(self, k: str):
return super().__delitem__(k) # type: ignore[arg-type]
def __setstate__(self, m: Mapping[_KT, _VT]) -> None:
return super().update(m)
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
__setstate__ = dict.update
@override
def __getstate__(self) -> Self: