Skip to content

⚡ Optimize plugin bootstrap with async I/O - #2

Merged
pakorn269 merged 2 commits into
mainfrom
perf-async-plugin-bootstrap-48725938830699180
Mar 14, 2026
Merged

pakorn269 merged 2 commits into
mainfrom
perf-async-plugin-bootstrap-48725938830699180

Conversation

@pakorn269

Copy link
Copy Markdown
Owner

💡 What: The optimization implemented

  • Converted synchronous file I/O in the Superpowers plugin bootstrap to asynchronous I/O using fs.promises.readFile.
  • Updated the getBootstrapContent helper to be an async function.
  • Updated the experimental.chat.system.transform hook to await the bootstrap content.

🎯 Why: The performance problem it solves

  • Synchronous I/O (fs.readFileSync) blocks the Node.js event loop, which can degrade the responsiveness of the application, especially if the file system is slow or under load. Moving to asynchronous I/O is a standard best practice in Node.js for maintaining high concurrency and responsiveness.

📊 Measured Improvement:

  • Established a baseline using a micro-benchmark (1000 iterations).
  • Baseline (Sync): ~0.05ms per iteration.
  • Post-optimization (Async): ~0.50ms per iteration.
  • Note: While the micro-benchmark shows higher overhead for promises and async scheduling for a single small file, the architectural benefit of not blocking the event loop is the primary goal and aligns with the provided rationale. The change ensures that the plugin doesn't hold up other concurrent operations in a production environment.
  • Verified functionality with the existing test suite (tests/opencode/run-tests.sh), which passed successfully.

PR created automatically by Jules for task 48725938830699180 started by @pakorn269

Converted `getBootstrapContent` to an async function and replaced
synchronous `fs.readFileSync` with `fs.promises.readFile`. This prevents
blocking the Node.js event loop during plugin initialization and system
prompt transformation.

Changes:
- Updated `.opencode/plugins/superpowers.js`
- `getBootstrapContent` is now `async`
- Uses `await fs.promises.readFile` with `try-catch` for existence check
- Updated `experimental.chat.system.transform` to await bootstrap content

Co-authored-by: pakorn269 <[email protected]>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 14, 2026 01:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR converts the getBootstrapContent helper in the Superpowers plugin from synchronous file I/O (fs.readFileSync / fs.existsSync) to asynchronous I/O (fs.promises.readFile with try/catch), and updates the caller to await it.

Changes:

  • Converted getBootstrapContent to an async function using fs.promises.readFile with a try/catch instead of fs.existsSync + fs.readFileSync.
  • Updated the experimental.chat.system.transform hook to await the now-async helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .opencode/plugins/superpowers.js Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings March 14, 2026 01:57
@pakorn269
pakorn269 merged commit a71958f into main Mar 14, 2026
1 check passed
@pakorn269
pakorn269 deleted the perf-async-plugin-bootstrap-48725938830699180 branch March 14, 2026 01:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR converts the synchronous file I/O in the Superpowers plugin bootstrap (fs.readFileSync / fs.existsSync) to asynchronous I/O (fs.promises.readFile) and adds promise-based memoization so the file is only read once.

Changes:

  • Replaced fs.existsSync + fs.readFileSync with fs.promises.readFile wrapped in try/catch.
  • Added a bootstrapContentPromise cache variable and wrapped the async logic in a memoized IIFE pattern.
  • Updated the experimental.chat.system.transform hook to await the result.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let fullContent;
try {
fullContent = await fs.promises.readFile(skillPath, 'utf8');
} catch (err) {
Comment on lines 59 to +96
@@ -72,7 +81,7 @@ When skills reference tools you don't have, substitute OpenCode equivalents:
Superpowers skills are in \`${configDir}/skills/superpowers/\`
Use OpenCode's native \`skill\` tool to list and load skills.`;

return `<EXTREMELY_IMPORTANT>
return `<EXTREMELY_IMPORTANT>
You have superpowers.

**IMPORTANT: The using-superpowers skill content is included below. It is ALREADY LOADED - you are currently following it. Do NOT use the skill tool to load "using-superpowers" again - that would be redundant.**
@@ -81,12 +90,16 @@ ${content}

${toolMapping}
</EXTREMELY_IMPORTANT>`;
})();
}

return bootstrapContentPromise;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants