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 - Cache-busted assets (?v=<mtime>) with a long-lived immutable browser cache
  • 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

Asset Optimization

CSS/JavaScript Delivery

Static theme and plugin assets are served and cache-managed by AssetLoader:

  • CSS served as source - File-level CSS minification is currently forced off in AssetLoader (the minifier broke some rules), so theme/plugin .css is delivered unchanged. JS minification follows the assets.minify_js setting, and any .min.css/.min.js shipped alongside a source file is served as-is. Inline <style>/<script> blocks (via InlineAssetHelper) are always minified.
  • Cache busting (since 5.7.2) - Every asset URL carries a ?v=<filemtime> query string, so the long-lived immutable browser cache (Cache-Control: max-age=31536000, immutable set in .htaccess/nginx) still serves the fresh file the moment it changes — no manual cache clear needed after a deploy or edit. This covers plugin assets too, since PluginAssetHelper delegates to AssetLoader.

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:

# Remove obsolete files in stockage/
php app/Cli/console.php cleanup:stockage

# Remove duplicate post files
php app/Cli/console.php cleanup:duplicate-posts

# Purge old anonymous visitor entries
php app/Cli/console.php cleanup:visitors

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