Clean up and optimize parts of WebAPIResource.

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

Information

Djblets
release-4.x

Reviewers

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.

Summary ID
Clean up and optimize parts of WebAPIResource.
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.
e4706c380d67fd34fefc65714a4168e4cdeea98a
Description From Last Updated

'typing_extensions.Literal' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

undefined name 'WebAPIResponsePayload' Column: 36 Error code: F821

reviewbotreviewbot

undefined name 'WebAPIResponsePayload' Column: 15 Error code: F821

reviewbotreviewbot

undefined name 'WebAPIResponseLinks' Column: 16 Error code: F821

reviewbotreviewbot

undefined name '_ExpandInfo' Column: 32 Error code: F821

reviewbotreviewbot

'typing.Set' imported but unused Column: 1 Error code: F401

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
Review request changed
Change Summary:

Removed unused imports and prematurely-added types.

Commits:
Summary ID
Clean up and optimize parts of WebAPIResource.
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.
c9022d54fc5d9ab0c338c524e9f2ba84bc8c9f18
Clean up and optimize parts of WebAPIResource.
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.
e4706c380d67fd34fefc65714a4168e4cdeea98a

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

david
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-4.x (427f074)