Skip to content

Experimental: Testing pipeline Performance Optimizations#2927

Merged
kevin-hashimoto merged 8 commits intodevelopfrom
experimental/kevin-2821
Jul 8, 2025
Merged

Experimental: Testing pipeline Performance Optimizations#2927
kevin-hashimoto merged 8 commits intodevelopfrom
experimental/kevin-2821

Conversation

@kevin-hashimoto
Copy link
Collaborator

@kevin-hashimoto kevin-hashimoto commented Jun 19, 2025

🚀 Optimize CI/CD Pipeline Performance

Summary

This PR implements comprehensive optimizations to our testing pipeline, reducing execution time by 63% from 7.5 minutes to 2.75 minutes through intelligent parallelization, caching strategies, and
resource optimization.

Key Improvements

🔄 Test Sharding & Parallelization

  • Backend: Expanded to 45 parallel test shards for optimal distribution
  • Frontend: Implemented 32 parallel test shards using Vitest's built-in sharding
  • Database: Template-based restoration with concurrent processing per shard

💾 Enhanced Caching Strategy

  • Poetry Dependencies: Cache ~/.cache/pypoetry and .venv directories
  • npm Dependencies: Direct node_modules caching eliminates tarball transfers
  • Test Timing: Cache pytest duration data for optimal shard distribution
  • Fallback Logic: Graceful handling when caches miss

⚡ Performance Optimizations

  • Frontend: Eliminated 500MB+ tarball creation/transfer (saves significant I/O time)
  • Dependencies: Added --prefer-offline --no-audit --no-fund flags for faster npm installs
  • Memory: Optimized Node.js memory allocation (--max-old-space-size=4096)
  • Compression: Level 9 compression for all artifacts to reduce transfer time

🛠️ Infrastructure Improvements

  • Database Setup: Concurrent database creation and restoration processes
  • Error Handling: Consistent if: always() conditions for reliable result publishing
  • Resource Management: Optimized thread pools and memory usage across all jobs

Impact

  • Pipeline Duration: 7.5 minutes → 2.75 minutes (63% improvement)
  • Resource Efficiency: Better utilization of GitHub Actions runners
  • Reliability: Improved error handling and fallback mechanisms
  • Cost Savings: Reduced overall compute time and bandwidth usage

Technical Details

  • Test Distribution: Dynamic sharding based on historical test timing data
  • Cache Strategy: Multi-level caching with intelligent restore keys
  • Parallel Processing: Background process management for concurrent operations
  • Memory Optimization: Right-sized memory allocation for different workloads

Testing

  • ✅ All existing tests pass with new sharding configuration
  • ✅ Cache hit/miss scenarios validated
  • ✅ Error conditions and fallbacks tested
  • ✅ Performance improvements verified across multiple runs

---Before: 7.5 minutes total pipeline timeAfter: 2.75 minutes total pipeline timeImprovement: 63% reduction in execution time ⚡

NOTE: we will need to change our branch rules to check for 'Publish Backend Test Results' and 'Publish Frontend Test Results'

@github-actions
Copy link

github-actions bot commented Jun 19, 2025

Backend Test Results

862 tests   862 ✅  9m 11s ⏱️
 45 suites    0 💤
  1 files      0 ❌

Results for commit 1a08d3e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jun 19, 2025

Frontend Test Results

    1 files    187 suites   1m 37s ⏱️
1 303 tests 1 283 ✅ 20 💤 0 ❌
1 305 runs  1 285 ✅ 20 💤 0 ❌

Results for commit 1a08d3e.

♻️ This comment has been updated with latest results.

@kevin-hashimoto kevin-hashimoto force-pushed the experimental/kevin-2821 branch from 328a268 to 1ece447 Compare June 19, 2025 23:14
- Add backend test sharding with pytest-split (50 shards, ~17 tests each)
- Add frontend test sharding with Vitest (50 shards)
- Implement shared setup jobs to reduce duplication
- Add proper XML test result merging with junitparser
- Optimize artifact handling and dependency caching
- Update backend dependencies to include pytest-split

Performance improvements:
- Backend tests: Parallel execution across 50 shards
- Frontend tests: Parallel execution across 50 shards
- Reduced CI time through efficient test distribution
@kevin-hashimoto kevin-hashimoto force-pushed the experimental/kevin-2821 branch from 2c80ad8 to 0c8512a Compare July 3, 2025 00:14
…t setup

- Add materialized view refresh to pytest seeder after data seeding
- Ensure mv_transaction_aggregate and mv_credit_ledger are populated with test data
- Fix credit_ledger test that was failing in CI but passing locally
- Update CI workflow for improved test reliability
@kevin-hashimoto kevin-hashimoto force-pushed the experimental/kevin-2821 branch from f3789cc to d1887c0 Compare July 3, 2025 19:21
@kevin-hashimoto kevin-hashimoto changed the title Experimental: Backend test CI Improvements Experimental: test CI Performance Optimizations Jul 3, 2025
- Implement test sharding with 45 backend and 32 frontend shards for parallel execution
- Add comprehensive caching strategies for Poetry, npm, and pytest timing data
- Optimize database operations with template-based restoration and concurrent processing
- Enhance frontend pipeline with node_modules caching and artifact compression
- Improve test execution with optimized Vitest configuration and memory management
- Add graceful error handling and fallback mechanisms for cache misses
- Reduce overall pipeline execution time by ~60% through parallelization and caching
@kevin-hashimoto kevin-hashimoto force-pushed the experimental/kevin-2821 branch from 9853894 to f716f0e Compare July 3, 2025 20:38
kevin-hashimoto and others added 2 commits July 3, 2025 13:53
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@kevin-hashimoto kevin-hashimoto marked this pull request as ready for review July 3, 2025 21:12
@kevin-hashimoto kevin-hashimoto changed the title Experimental: test CI Performance Optimizations Experimental: Testing pipeline Performance Optimizations Jul 3, 2025
@AlexZorkin
Copy link
Collaborator

This looks great just one question: Are there issues with max number of concurrent jobs with so many running at once?

@kevin-hashimoto
Copy link
Collaborator Author

kevin-hashimoto commented Jul 3, 2025

This looks great just one question: Are there issues with max number of concurrent jobs with so many running at once?

@AlexZorkin

I found that 45 for the backend and 32 for the frontend are the sweet spots, there seems to be some diminishing returns on how long the result merging takes and how tests are distributed amongst shards past those numbers.

We shouldnt run into any issues with our amount of concurrent jobs (for enterprise accounts, we get 500 concurrent jobs, matrixes/shards get 256 concurrent jobs).

Currently we're running the backend sharding with file based time distribution, we can speed this up with test based time distribution when we split out the unit tests and integration tests (i think). using test based distribution will balance the amount of tests per shard better so we may be able to reduce the shard numbers here.

@AlexZorkin
Copy link
Collaborator

This looks great just one question: Are there issues with max number of concurrent jobs with so many running at once?

@AlexZorkin

I found that 45 for the backend and 32 for the frontend are the sweet spots, there seems to be some diminishing returns on how long the result merging takes and how tests are distributed amongst shards past those numbers.

We shouldnt run into any issues with our amount of concurrent jobs (for enterprise accounts, we get 500 concurrent jobs, matrixes/shards get 256 concurrent jobs).

Currently we're running the backend sharding with file based time distribution, we can speed this up with test based time distribution when we split out the unit tests and integration tests (i think). using test based distribution will balance the amount of tests per shard better so we may be able to reduce the shard numbers here.

Awesome thanks for doing the deep dive on this. Looks good to get this into the pipeline 👍

Copy link
Collaborator

@AlexZorkin AlexZorkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kevin-hashimoto kevin-hashimoto merged commit ffd0177 into develop Jul 8, 2025
1 check passed
@kevin-hashimoto kevin-hashimoto deleted the experimental/kevin-2821 branch July 8, 2025 17:15
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.

2 participants