Optimize performance and fix plugin loading logic#53
Merged
MarcosBrendonDePaula merged 2 commits intomainfrom Feb 12, 2026
Merged
Optimize performance and fix plugin loading logic#53MarcosBrendonDePaula merged 2 commits intomainfrom
MarcosBrendonDePaula merged 2 commits intomainfrom
Conversation
- Fix infinite recursion in PluginModuleResolver.cacheSet() (stack overflow on first cache write) - Fix timeout timer leak in PluginManager.executePluginHook() (clearTimeout after race) - Replace O(n) Array.includes() with Set lookup for enabled plugins check - Replace broken topological sort + .sort() with Kahn's algorithm that respects both dependency constraints and priority within each dependency level - Cache isDevelopment() at module load in vite plugin (avoids per-request eval) - Cap histogram values array at 1000 entries in monitoring plugin (prevents unbounded memory growth) - Cache os.cpus().length in monitoring system metrics collector (avoids expensive syscall per interval) - Reuse shared DefaultPluginConfigManager instance in createPluginUtils() - Defer PluginDiscovery singleton instantiation (unused, was eagerly allocated at import) https://claude.ai/code/session_017p98YBiey4Jb8HaLeuLNAQ
- Pre-scan all build output files at startup into a Map for O(1) lookups (replaces per-request statSync syscalls that blocked the event loop) - Cache Bun.file() handles to avoid re-creating them on repeated requests - Pre-resolve index.html once for SPA fallback (was recalculated per request) - Fast pathname extraction without full URL parse (string ops vs new URL()) - Conditional decodeURIComponent only when '%' is present - Add Cache-Control: immutable for hashed assets (e.g. app.abc123.js) https://claude.ai/code/session_017p98YBiey4Jb8HaLeuLNAQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves performance across multiple systems through caching, algorithmic optimization, and memory management, while fixing critical issues in plugin dependency resolution and resource cleanup.
Key Changes
Vite Plugin Static File Serving (core/plugins/built-in/vite/index.ts)
Mapfor O(1) lookup performance.[0-9a-f]{8,}.\w+$(content-hashed) now returnCache-Control: public, max-age=31536000, immutableheadersURLobject parsing with manual string operations to avoid unnecessary allocationsisDevelopment()call to module load sinceNODE_ENVdoesn't change at runtimePlugin Registry Load Order (core/plugins/registry.ts)
Plugin Manager Hook Execution (core/plugins/manager.ts)
clearTimeout()in finally block to prevent timer leaks when hooks complete before timeoutArray.includes()withSet.has()for O(1) lookup instead of O(n)Monitoring Plugin (core/plugins/built-in/monitoring/index.ts)
os.cpus().lengthoutside the collection loop since CPU count is immutable at runtimePlugin Discovery (core/plugins/discovery.ts)
pluginDiscoveryfrom eager singleton to lazy-initialized functiongetPluginDiscovery()to avoid side effects at module loadPluginRegistrynow handles discovery directlyPlugin Config Manager (core/plugins/config.ts)
sharedConfigManagerinstance fordeepMerge()andvalidateSchema()utilities since the manager is statelessPlugin Module Resolver (core/plugins/module-resolver.ts)
this.cacheSet()should bethis.resolveCache.set()Notable Implementation Details
https://claude.ai/code/session_017p98YBiey4Jb8HaLeuLNAQ