1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-12-04 18:56:44 +01:00

perf(twitter): optimize tweet and thread archiving pipeline

Accelerates tweet and thread archiving times by up to 11x on live
Twitter and reduces processing overhead across Python and Rust:

- In-memory GraphQL thread caching: parse and cache all tweets returned
  in TweetDetail conversation timeline (threaded_conversation_with_injections_v2),
  resolving parent/replied-to tweets in threads immediately without
  redundant network round-trips.
- Proactive rate limiting: replace blind 2.0s post-save sleep with proactive
  throttling prior to outgoing HTTP requests, eliminating trailing sleep on
  single tweets and intermediate sleep for cached thread tweets.
- HTTP keep-alive connection reuse: reuse scraper session for downloading
  media assets and avatars, avoiding fresh TCP/TLS handshakes per asset.
- Avatar & media deduplication: skip avatar download if target file already
  exists on disk.
- Lightweight client startup: introduce SimpleTwitterScraper using direct
  httpx.Client with authenticated headers and lazy twitter.scraper fallback,
  eliminating ~30ms of module imports at startup.
- Fast JSON I/O: use orjson for binary JSON parsing and indented serialization.
- Rust database batching: wrap entry creation, blob upserts, artifact
  registration, and run completion in a single SQLite transaction, reducing
  fsyncs from ~19 down to 1.
- In-memory blob caching: cache blob records across tweet artifacts to
  avoid repeated filesystem metadata stats and duplicate upserts.
- Single-pass staging: rewrite and move staged JSON files directly to
  raw_tweets/ in a single pass without intermediate staging writes.
- Zero-copy metadata deserialization: use borrowed TweetJsonMetadata struct
  to extract title/metadata without dynamic Value heap allocations.
- Regex fast paths: add substring gates before compiling/iterating asset regexes.
This commit is contained in:
TheGeneralist 2026-10-21 20:28:18 +02:00
parent af6ff514ed
commit 8973a514cc
5 changed files with 442 additions and 297 deletions

7
.gitignore vendored
View file

@ -23,6 +23,9 @@ crates/archivr-server/static/**
!vendor
!vendor/**
vendor/**/__pycache__/
vendor/**/__pycache__/**
vendor/**/*.pyc
!flake.nix
!flake.lock
@ -52,4 +55,8 @@ frontend/result
frontend/result/**
frontend/dist/
frontend/dist/**
!autoresearch.sh
!benches/
!benches/**
.DS_Store