# Cutting test time 4x and scan overhead on one SQLite VPS

CrawlWise runs on one European VPS: Rails 8, SQLite with Solid Queue, and a separate Node plus
Playwright container for Chromium scans. Before adding more features or chasing traffic, we spent
12 commits measuring where CPU, memory, database time and test minutes were going.

Every number below was measured locally on 24 November 2026 across 667 RSpec examples and 356
Vitest tests, without changing check outputs or dropping assertions.

## 1. An O(N²) sitemap rebuild in PublicPage

Profiling RSpec (`bin/rspec --profile`) showed that a single request to `/sitemap.xml` took
roughly 1.8 seconds in test, and every public HTML page was rebuilding the site catalog on each
render.

Every public page in CrawlWise lives in `PublicPage`: static views, guides, free checkers and blog
posts across English and Polish. On each request, the header, footer, `hreflang` helper and
`Link` header called `PublicPage.all`, `PublicPage.find_translation` and `PublicPage#alternates`
around 19 times. None of those lookups were indexed, and in non-production environments each call
re-read and YAML-parsed every Markdown file on disk. In `sitemap.xml`, calling `alternates` inside
the loop over all pages turned sitemap generation into O(N²) rebuilds.

The fix had three parts:

- Cache `Guide`, `Tool`, `BlogPost` and `ResearchReport` catalogs (permanently in production,
  invalidated by path and `mtime` in development and when tests stub a directory).
- Cache rendered Kramdown HTML per `(locale, markdown)` instead of re-parsing Markdown on every
  request.
- Build an O(1) lookup catalog on `PublicPage` (`by_locale`, `by_key`, `by_translation`,
  `alternates_by_translation`) and O(1) key indexes on `Checkset` and `SiteCheckset`.

We also switched `SampleReport.load!` from 58 individual `create!` inserts to bulk `insert_all!`
and stopped loading the sample report fixture in specs that never visit `/sample-report`.

RSpec dropped from 63.7 seconds (89.4 seconds with `--profile`) to 15.35 seconds.

## 2. Fewer SQLite queries and conditional GET on Markdown

Next we looked at database work during report views:

- `SiteAuditReport#page_table` ran 6 separate `COUNT(*)` queries (one per filter tab: all, errors,
  missing title, thin, slow, noindex). Collapsing them into one `SUM(CASE WHEN ... THEN 1 ELSE 0 END)`
  query cut 6 scans of `site_audit_pages` to 1.
- `SiteAuditsController#show` built `@page_table` even for `.json` and `.md` exports that never
  render it, and `ScanReport` ran three separate `scan_pages` lookups instead of preloading by
  `kind`.
- Public `.md` endpoints for guides, blog posts, tools and `/seo-audit` sent `Cache-Control: public,
  max-age=300` without an ETag, so revalidating crawlers received full 200 responses instead of
  `304 Not Modified`. Adding `fresh_when` closed that gap.
- In `database.yml`, we added `temp_store: memory`, `cache_size: -16000` (16 MB) and
  `mmap_size: 134217728` (128 MB) to SQLite's connection pragmas.

While reading the cookie-free traffic middleware (`PageViewCounter`), we also caught a privacy bug:
`/r/:token` was excluded so private page-audit tokens never entered `page_views`, while `/sa/:token`
and `/pl/sa/:token` were missing from the skip pattern. Private site-audit links now stay out of
the table and finished reports are counted under the generic path `/sa/:token`, matching what our
[privacy page](/privacy) promises.

## 3. 70% smaller fonts and security headers

CrawlWise ships zero JavaScript on static content pages, so web fonts were the heaviest asset on a
cold load. Four weights of IBM Plex Mono were still served as uncompressed `.ttf` files totaling
512 KB. Compressing them with `woff2_compress` brought the same four weights down to 152 KB,
and we added `<link rel="preload" as="font">` for the regular weight.

We also fixed a few things our own checks look for: a restrictive `Permissions-Policy` header
(verified by our [security headers checker](/tools/security-headers-checker)), Atom feed
autodiscovery on `/` and `/pl`, `og:locale:alternate` on translated pages, `wordCount` and
`timeRequired` on article JSON-LD, and previous/next links between guides.

## 4. Overlapping HTTP probes with Chromium in the scanner

A CrawlWise page audit runs under a 90-second budget. Previously, the scanner fetched `robots.txt`
and raw HTML, then ran `collectSiteSnapshot` (sitemap expansion, 6 AI bot fetches, 10
`/.well-known/` checks, feeds, TLS inspection and 6 sequential host-variant and soft-404 probes),
and only after all of that finished did it launch the desktop Chromium render.

Those HTTP probes do not depend on Chromium, and Chromium only needs `robots.txt` and the target
URL. Running `collectSiteSnapshot` in parallel with the primary desktop `renderPage` overlaps the
two slowest phases instead of stacking them end to end.

Inside the scanner we made five more targeted cuts:

- Shared one validating `EgressProxy` across desktop, mobile and extra-page renders within a scan
  instead of starting and stopping up to four local proxy servers per scan.
- Combined four sequential `page.evaluate` calls (vitals, fonts, WebMCP tools, render-blocking
  counts) into one IPC round-trip.
- Reused a single `TurndownService` instance and stopped converting HTML to Markdown when the
  caller only needed plain text length (such as AI bot parity fetches and site-audit template
  samples).
- Replaced double-copied chunk arrays in `fetchPage` with zero-copy `Buffer` views.
- Moved the 64-bit `simhash64` inner loop from per-bit `BigInt` shifts to two 32-bit integer
  halves, producing the identical 16-character hex fingerprint with no inner-loop BigInt
  allocations.

Indexing callback captures by `scan_id` in the scanner test suite let Playwright render and runner
tests run with `it.concurrent` over a shared egress proxy, cutting Vitest from 26.25 seconds to
11.53 seconds.

## Before and after

| Area | Before | After |
| --- | ---: | ---: |
| RSpec suite (667 examples) | 63.7 s | 15.35 s |
| Vitest suite (356 tests) | 26.25 s | 11.53 s |
| IBM Plex Mono font payload (4 weights) | 512 KB (TTF) | 152 KB (WOFF2) |
| Site-audit page filter counts | 6 SQL queries | 1 SQL query |
| Desktop render DOM snapshot IPC calls | 4 round-trips | 1 round-trip |

You can see how the checks work in the [methodology](/methodology), inspect a live
[sample report](/sample-report), or test your own domain with the [whole-site audit](/seo-audit).

---

Last updated 25 November 2026.

HTML version: <https://crawlwise.dev/blog/cutting-test-time-and-scan-overhead-on-one-vps>

Every CrawlWise page in Markdown: <https://crawlwise.dev/llms.txt>
