Clean up and optimize parts of WebAPIResource.

Review Request #13278 — Created Sept. 19, 2023 and submitted — Latest diff uploaded




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 of hasattr or in 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 one if 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.