Skip to content

Optimize DPL classifier with pre-serialized snapshot#113

Open
lucasfeliciano wants to merge 11 commits intoPauperformance:masterfrom
lucasfeliciano:classifier-snapshot-optimization
Open

Optimize DPL classifier with pre-serialized snapshot#113
lucasfeliciano wants to merge 11 commits intoPauperformance:masterfrom
lucasfeliciano:classifier-snapshot-optimization

Conversation

@lucasfeliciano
Copy link
Collaborator

Summary

  • Add from_snapshot_data and from_snapshot classmethods to Decklassifier for loading from pre-built pickle files
  • Create build_snapshot.py script that runs the expensive initialization once and serializes all classifier state (archetypes, training decks, reference deck cache, artifact land names) into a single file
  • Update silver.py to load from snapshot on startup with fallback to full initialization
  • Decouple _is_affinity from Scryfall API by supporting pre-loaded artifact land names
  • Add make build-snapshot target

This reduces classifier cold start from minutes to under 5 seconds by eliminating runtime dependencies on Dropbox, Scryfall, and MTGGoldfish. Enables potential Lambda/serverless deployment.

Test Plan

  • 6 new tests in test_decklassifier.py covering snapshot creation, loading, classification, and edge cases
  • All 22 existing tests pass (2 skipped - secrets-based)
  • black and isort formatting verified
  • Run make build-snapshot on a machine with Dropbox/MTGGoldfish credentials to generate the snapshot
  • Deploy with snapshot and verify classification results match previous behavior

Pre-serialize classifier state to a single pickle file to reduce
cold start time from minutes to under 5 seconds, enabling potential
Lambda/serverless deployment.
8 tasks covering: Decklassifier changes, build script, snapshot
loading, silver.py updates, Makefile target, and testing.
…om Scryfall

Add _artifact_land_names field to Decklassifier and a from_snapshot_data
classmethod that constructs a Decklassifier without requiring
PauperformanceService. The _is_affinity method now uses pre-loaded
artifact land names when available, falling back to Scryfall otherwise.

Move PauperformanceService and MTGGoldfish imports behind TYPE_CHECKING
and local scope respectively to allow importing Decklassifier without
triggering heavy service initialization side effects.
…nceService

Also fix _cosine_similarity to handle empty vectors (e.g. empty sideboards)
by returning 1 when vector length is 0, preventing NaN from scipy.
…s None

When classify_deck encounters an uncached reference deck and
pauperformance is None (snapshot mode), skip it instead of crashing.
This allows the classifier to fall back to known_decks for matching.
Move heavy imports inside get_dpl_classifier() so they're only loaded
on fallback. Add load_dpl_classifier() that tries snapshot first.
- Extract CLASSIFIER_SNAPSHOT_PATH to shared constant in silver.py
- Add os.makedirs in build_snapshot for robustness
- Add negative Affinity detection test
- Add .gitignore entry for classifier_snapshot.pkl
- Fix duplicate CLASSIFIER_ prefix from replace_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant