Skip to main content

Overview

Percify performance strategy focuses on query consolidation, targeted indexing, and selective caching. Internal improvements documented in feed and dashboard optimization guides are summarized here for end users and integrators.

Key Improvements

AreaTechniqueResult
Dashboard CountsUNION + filtered COUNT800ms → ~150ms
Feed/Explore Query9 targeted indexes1900ms → 500–700ms
CachingCDN + stale-while-revalidateCache hits ~50–100ms
Counting StrategyApprox reltuples estimatesReduced expensive window functions

Dashboard Aggregation Pattern

WITH counts AS (
  SELECT 
    COUNT(*) FILTER (WHERE source = 'avatars') as avatar_count,
    COUNT(*) FILTER (WHERE source = 'videos') as video_count,
    COUNT(*) FILTER (WHERE source = 'voices') as voice_count,
    COUNT(*) FILTER (WHERE source = 'likes') as liked_count
  FROM (
    SELECT 'avatars' FROM user_generated_avatars WHERE user_id = $1 AND COALESCE(hidden_from_feed,false)=false
    UNION ALL
    SELECT 'videos' FROM user_video_files WHERE user_id = $1
    UNION ALL
    SELECT 'voices' FROM user_audio_files WHERE user_id = $1
    UNION ALL
    SELECT 'likes' FROM avatar_likes WHERE user_id = $1
  ) combined
)
SELECT * FROM counts;

Feed Query Principles

PrincipleBenefit
Remove COUNT(*) OVERAvoid full-table scans
Replace EXISTS with LEFT JOINUtilize composite indexes
Partial indexes on visibilityReduce filtered row set
Separate trending indexFaster popularity sorting

Caching Strategy

HeaderValue
Cache-Controlpublic, max-age=300, stale-while-revalidate=600
VaryAccept-Encoding
Use short TTL for freshness + long stale window for resilience.

Monitoring Recommendations

  • Log query durations >500ms
  • Record generation job queue latency percentiles
  • Track cache hit ratios per endpoint

Scalability Tips for Integrators

ScenarioRecommendation
Burst avatar generationQueue jobs + show optimistic UI
Large feed paginationUse estimated total counts for infinite scroll
High video durationsBatch long renders off peak
Heavy audio synthesisReuse voice profiles to skip cloning cost

Future Enhancements

  • Materialized view fallback for extreme volumes
  • Adaptive cost suggestions (dynamic UX based on balance)
  • Background warm-up of popular assets

Troubleshooting

SymptomCauseAction
Slow dashboard loadMissing indexesRe-run optimization migration
Feed latency spikesCold cache / index bloatVACUUM ANALYZE + ensure CDN caching
Generation queue delaysConcurrency saturationIncrease worker pool or throttle client
  • [/percify/architecture]
  • [/percify/credits]
  • [/percify/faq]

Have questions? See [/percify/faq].