Clean up and optimize parts of WebAPIResource.
Review Request #13278 — Created Sept. 19, 2023 and submitted
This reworks some of
WebAPIResource
to reduce unnecessary busywork and
reorganize some blocks of code to help with maintenance, performance,
and memory.Initial state setup for resources no longer allocates more memory for
allowed_mimetypes
when there's no vendor required for resources
(though a vendor is recommended).Dynamically-created state caches and key lookups are now accessed via a
try/except
rather than a series ofhasattr
orin
calls, which is
faster overall and especially in the common case. Some caches are now
built with reduced loops or overhead.Object serialization now computes all request-specific code (cache
setup, expanded resources) up-front in oneif request:
, in order to
make it clear what's state setup and what's payload building.Some unnecessary
isinstance
checks,if
conditions, attribute
lookups, and list allocations have been removed.Some string building has been replaced with f-strings.
Small optimizations that add up, saving a few seconds in my typical unit
test runs for Review Board's API test suite.
Djblets and Review Board test suites pass.
Summary | ID |
---|---|
e4706c380d67fd34fefc65714a4168e4cdeea98a |
Description | From | Last Updated |
---|---|---|
'typing_extensions.Literal' imported but unused Column: 1 Error code: F401 |
reviewbot | |
undefined name 'WebAPIResponsePayload' Column: 36 Error code: F821 |
reviewbot | |
undefined name 'WebAPIResponsePayload' Column: 15 Error code: F821 |
reviewbot | |
undefined name 'WebAPIResponseLinks' Column: 16 Error code: F821 |
reviewbot | |
undefined name '_ExpandInfo' Column: 32 Error code: F821 |
reviewbot | |
'typing.Set' imported but unused Column: 1 Error code: F401 |
reviewbot |
- Change Summary:
-
Removed unused imports and prematurely-added types.
- Commits:
-
Summary ID c9022d54fc5d9ab0c338c524e9f2ba84bc8c9f18 e4706c380d67fd34fefc65714a4168e4cdeea98a - Diff:
-
Revision 2 (+604 -480)