ladybird/Libraries/LibHTTP
Aliaksandr Kalenik 14dc9e8ca2 LibHTTP: Short-circuit CacheIndex eviction when under its size limit
remove_entries_exceeding_cache_limit() is called after every network
response, but the cache is usually still under budget and nothing needs
to evict. Every one of those calls currently still runs the
window-function eviction SQL over the whole CacheIndex table just to
conclude there is nothing to do.

Short-circuit the call when the cache is already within its configured
size limit. To make that check cheap, maintain m_total_estimated_size
as a running total of the cache's estimated byte size, so the no-op
case becomes a single u64 compare and the DB is only touched when
there is real work.

Bookkeeping:
- Seed the total in CacheIndex::create() via a new
  select_total_estimated_size statement (COALESCE(..., 0) so an empty
  index returns 0 rather than NULL).
- Each Entry caches serialized_request_headers_size and
  serialized_response_headers_size so we don't re-serialize to
  recompute its footprint; Entry::estimated_size() centralizes the
  arithmetic.
- create_entry() adds the new entry's size. Any row it displaces is
  removed via DELETE ... RETURNING so the total stays accurate even
  for entries that were never loaded into m_entries.
- remove_entry() and the bulk DELETE statements were extended with
  the same RETURNING clause for the same reason.
- update_response_headers() shifts the total by the signed delta
  between old and new serialized header size.

Also COALESCEs estimate_cache_size_accessed_since over an empty table
to 0 so callers don't have to special-case NULL.
2026-04-19 01:31:37 +02:00
..
Cache LibHTTP: Short-circuit CacheIndex eviction when under its size limit 2026-04-19 01:31:37 +02:00
Cookie LibHTTP: Remove unused header in ParsedCookie 2026-02-23 12:15:23 +01:00
CMakeLists.txt LibHTTP+LibWebView+RequestServer: Allow users to set disk cache limits 2026-02-13 10:20:52 -05:00
Forward.h LibHTTP+LibWeb: Move the IncludeCredentials enum to LibHTTP 2026-02-10 12:21:20 +01:00
Header.cpp LibRegex: Add ECMAScriptRegex and migrate callers 2026-03-27 17:32:19 +01:00
Header.h LibHTTP: Return a StringView from HTTP::normalize_header_value 2026-02-26 22:27:46 +01:00
HeaderList.cpp LibHTTP: Remove unused header in HeaderList 2026-02-23 12:15:23 +01:00
HeaderList.h LibHTTP: Correctly normalize header whitespace in cache utilities 2026-02-26 22:27:46 +01:00
HTTP.cpp LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
HTTP.h LibRegex: Add ECMAScriptRegex and migrate callers 2026-03-27 17:32:19 +01:00
HttpRequest.cpp LibHTTP: Remove unused header in HttpRequest 2026-02-23 12:15:23 +01:00
HttpRequest.h LibHTTP: Remove unused header in HttpRequest 2026-02-23 12:15:23 +01:00
Method.cpp LibRegex: Add ECMAScriptRegex and migrate callers 2026-03-27 17:32:19 +01:00
Method.h LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
Status.h LibHTTP+LibWeb: Remove unused HTTP::HTTPResponse 2025-11-27 14:57:29 +01:00