Performance Optimization

Performance Optimization

Performance Overview

Flatboard 5 is designed for performance:

  • Denormalized Counters - Fast statistics without complex queries
  • Markdown Caching - Pre-rendered Markdown content
  • Atomic File Operations - Safe concurrent file access
  • Asset Optimization - Minified and combined assets
  • Efficient Storage - Optimized JSON/SQLite access

Caching

Markdown Cache

Flatboard 5 caches rendered Markdown:

  • Automatic Caching - Markdown is cached after first render
  • Cache Invalidation - Cache cleared when content updated
  • Performance Gain - Up to 70% faster page loads

Enable/Disable:

  • Admin Panel > Settings > Performance > Enable Cache

Template Cache

Cache compiled templates:

  • Faster Rendering - Templates compiled once
  • Reduced CPU - Less processing per request
  • Automatic Updates - Cache cleared on template changes

Cache Management

Clear Cache:

  • Admin Panel > Tools > Cache > Clear Cache

Rebuild Cache:

  • Admin Panel > Tools > Cache > Rebuild Cache
# Clear cache via CLI
php app/Cli/console.php cache:clear

# Rebuild cache
php app/Cli/console.php cache:rebuild

Asset Optimization

CSS/JavaScript Minification

Flatboard 5 automatically minifies assets:

  • Automatic - Minification happens automatically
  • Cache Busting - Versioned filenames for cache invalidation
  • Combined Files - Multiple files combined when possible
  • Debug Mode Override - When debug mode is enabled, assets are not minified (served in original format for easier debugging)

Configuration:

  • Admin Panel > Settings > Performance > Asset Optimization

Image Optimization

Optimize images before upload:

  • Compress Images - Use tools like TinyPNG
  • Correct Formats - Use WebP when possible
  • Appropriate Sizes - Resize to needed dimensions
  • Lazy Loading - Load images on demand

CDN Integration

Use a CDN for static assets:

  1. Configure CDN - Set CDN URL in settings
  2. Upload Assets - Upload to CDN
  3. Update Paths - Update asset paths
  4. Test - Verify CDN delivery

Storage Optimization

JSON Storage

Optimize JSON storage:

  • Regular Cleanup - Remove old/unused data
  • Archive Old Content - Move old discussions to archive
  • Optimize Structure - Keep JSON files organized

SQLite Optimization (Pro Edition)

Optimize SQLite database:

-- Vacuum database
VACUUM;

-- Analyze tables
ANALYZE;

-- Reindex
REINDEX;

Via Admin Panel:

  • Admin Panel > Tools > Database > Optimize

Storage Cleanup

Regular cleanup tasks:

# Clean old cache files
php app/Cli/console.php cleanup:cache

# Clean empty discussions
php app/Cli/console.php cleanup:empty-discussions

# Clean old storage
php app/Cli/console.php cleanup:storage

Server Optimization

PHP Configuration

Optimize PHP settings:

; Increase memory limit
memory_limit = 256M

; Optimize opcache
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000

; Increase execution time if needed
max_execution_time = 60

Web Server Configuration

Apache:

# Enable compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>

# Enable caching
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
</IfModule>

Nginx:

# Enable compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;

# Enable caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

Database Optimization (Pro Edition)

Indexes

Ensure proper indexes:

-- Check indexes
.schema

-- Create indexes if needed
CREATE INDEX idx_discussion_category ON discussions(category_id);
CREATE INDEX idx_post_discussion ON posts(discussion_id);
CREATE INDEX idx_user_email ON users(email);

Query Optimization

Optimize queries:

  • Use Indexes - Ensure indexes on frequently queried columns
  • Limit Results - Use LIMIT for large result sets
  • Avoid N+1 - Batch queries when possible
  • Use Transactions - Group related operations

Monitoring Performance

Performance Metrics

Monitor key metrics:

  • Page Load Time - Target: < 2 seconds
  • Database Queries - Minimize query count
  • Memory Usage - Monitor PHP memory
  • CPU Usage - Watch server CPU

Tools

Browser DevTools:

  • Network tab - Check load times
  • Performance tab - Profile page rendering

Server Monitoring:

  • PHP-FPM status
  • Server resource usage
  • Database query logs

Performance Testing

Test performance:

  1. Load Testing - Use tools like Apache Bench
  2. Profile Code - Use Xdebug profiler
  3. Monitor Logs - Check error and access logs
  4. User Feedback - Gather user experience feedback

Best Practices

General

  • Enable Caching - Always enable caching in production
  • Optimize Assets - Minify and compress assets
  • Use CDN - Serve static assets from CDN
  • Monitor Performance - Regular performance monitoring

Content

  • Limit Post Length - Encourage concise posts
  • Optimize Images - Compress images before upload
  • Archive Old Content - Move old discussions to archive
  • Regular Cleanup - Clean up old/unused data

Server

  • Use PHP 8.1+ - Latest PHP versions are faster
  • Enable OPcache - Enable PHP OPcache
  • Use SSD Storage - Faster disk I/O
  • Adequate Resources - Ensure sufficient RAM/CPU

Troubleshooting

Slow Page Loads

Check:

  1. Cache is enabled
  2. Assets are optimized
  3. Server resources adequate
  4. Database queries optimized
  5. Network latency

High Memory Usage

Solution:

  1. Increase PHP memory limit
  2. Optimize queries
  3. Reduce cache size
  4. Review plugins

Database Slow

Solution:

  1. Add indexes
  2. Optimize queries
  3. Vacuum database (SQLite)
  4. Consider JSON storage for small sites

Resources

Last updated: February 23, 2026