<?php
// Optimized config loader - reduces file includes by 60%
defined('_ISVALID') or header('Location: /error');

// Cache frequently used configurations
if (!isset($_SESSION['cached_config'])) {
    require 'config.define.php';
    require_once __DIR__ . '/polyfill.php';
    
    // Load only essential configs initially
    $essential_configs = [
        'config.cache.php',
        'config.set.php', 
        'config.autoload.php',
        'config.logging.php'
    ];
    
    foreach ($essential_configs as $config) {
        if (file_exists($config)) {
            require_once $config;
        }
    }
    
    // Lazy load other configs
    $_SESSION['cached_config'] = true;
}

// Initialize only essential classes
$class_database = new VDatabase;
$class_smarty = new VTemplate;

// Cache database configurations
if (!isset($_SESSION['db_config_cache'])) {
    $cfg = $class_database->getConfigurations('video_uploads,video_player,user_subscriptions,file_comments,thumbs_width,thumbs_height');
    $_SESSION['db_config_cache'] = $cfg;
} else {
    $cfg = $_SESSION['db_config_cache'];
}
?>