Cutting test time 4x and scan overhead on one SQLite VPS
How 12 commits cut RSpec from 63.7s to 15.3s, Vitest from 26.2s to 11.5s, font weight by 70%, and overlapped Chromium renders with HTTP probes.
Published · 5 min read
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,BlogPostandResearchReportcatalogs (permanently in production, invalidated by path andmtimein 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 onChecksetandSiteCheckset.
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_tableran 6 separateCOUNT(*)queries (one per filter tab: all, errors, missing title, thin, slow, noindex). Collapsing them into oneSUM(CASE WHEN ... THEN 1 ELSE 0 END)query cut 6 scans ofsite_audit_pagesto 1.SiteAuditsController#showbuilt@page_tableeven for.jsonand.mdexports that never render it, andScanReportran three separatescan_pageslookups instead of preloading bykind.- Public
.mdendpoints for guides, blog posts, tools and/seo-auditsentCache-Control: public, max-age=300without an ETag, so revalidating crawlers received full 200 responses instead of304 Not Modified. Addingfresh_whenclosed that gap. - In
database.yml, we addedtemp_store: memory,cache_size: -16000(16 MB) andmmap_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 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), 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
EgressProxyacross 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.evaluatecalls (vitals, fonts, WebMCP tools, render-blocking counts) into one IPC round-trip. - Reused a single
TurndownServiceinstance 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
fetchPagewith zero-copyBufferviews. - Moved the 64-bit
simhash64inner loop from per-bitBigIntshifts 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, inspect a live sample report, or test your own domain with the whole-site audit.
Check your own site
Run a free 25-page preview of the whole-site audit. No account needed.
More from the blog
Last updated .