Skip to content

Comments

⚡ Bolt: Async stream optimization for static files#93

Draft
Dexploarer wants to merge 1 commit intomainfrom
bolt-static-streams-6346858301705708063
Draft

⚡ Bolt: Async stream optimization for static files#93
Dexploarer wants to merge 1 commit intomainfrom
bolt-static-streams-6346858301705708063

Conversation

@Dexploarer
Copy link
Owner

⚡ Bolt: Optimized static file serving to use async streams.

💡 What: Replaced synchronous fs.readFileSync with fs.createReadStream and fs.statSync with fs.promises.stat in src/api/server.ts.
🎯 Why: Reading files synchronously blocks the Node.js event loop, which degrades performance and responsiveness, especially for larger assets or under concurrent load.
📊 Impact: Improves server throughput and responsiveness by offloading file I/O to the thread pool and streaming content.
🔬 Measurement: Verified logic correctness; manual verification test created (but not included due to env constraints). The change aligns with Node.js best practices for static file serving.


PR created automatically by Jules for task 6346858301705708063 started by @Dexploarer

Replaces synchronous `fs.statSync` and `fs.readFileSync` with asynchronous `fs.promises.stat` and `fs.createReadStream` in `serveStaticUi` to prevent blocking the event loop during static asset serving. This improves server responsiveness under load.

- Adds `streamStaticResponse` helper for piping streams to response
- Updates `handleRequest` to await `serveStaticUi`
- Ensures proper error handling for file streams
@google-labs-jules
Copy link

👋 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.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bolt-static-streams-6346858301705708063

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Dexploarer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the performance and responsiveness of static file serving by migrating from synchronous, blocking file I/O operations to asynchronous streaming. This change offloads file reading to the thread pool and allows the server to handle more concurrent requests without degrading performance, particularly for larger assets.

Highlights

  • Asynchronous File I/O: Replaced synchronous file reading (fs.readFileSync) and file status checks (fs.statSync) with their asynchronous, promise-based and stream-based counterparts (fs.promises.stat and fs.createReadStream) to prevent blocking the Node.js event loop.
  • Static File Streaming: Introduced a new streamStaticResponse function to efficiently stream static file content to the client, improving server responsiveness and throughput.
  • Performance Optimization: The serveStaticUi function was refactored to be asynchronous and utilize the new streaming mechanism, aligning with Node.js best practices for serving static assets.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/api/server.ts
    • Added a new streamStaticResponse function to handle streaming static file content, including error handling and support for HEAD requests.
    • Modified the serveStaticUi function to be asynchronous and return a Promise<boolean>.
    • Updated serveStaticUi to use fs.promises.stat for asynchronous file status retrieval.
    • Replaced fs.readFileSync with fs.createReadStream within serveStaticUi to enable file streaming.
    • Changed the call from sendStaticResponse to the newly introduced streamStaticResponse in serveStaticUi.
    • Updated the handleRequest function to await the serveStaticUi call, reflecting its new asynchronous nature.
Activity
  • PR created automatically by Jules for task 6346858301705708063, initiated by @Dexploarer.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes static file serving by switching from synchronous file reads to asynchronous streams. This is a great performance improvement that avoids blocking the Node.js event loop. The changes in src/api/server.ts correctly replace fs.readFileSync with fs.createReadStream and make the serving function asynchronous.

I've added one comment to make the new streaming logic more robust by handling client disconnects and improving error handling, which will prevent potential resource leaks.

Comment on lines +1712 to +1721
stream.pipe(res);
stream.on("error", (err) => {
logger.error(
`[milady-api] Static stream error: ${err instanceof Error ? err.message : err}`,
);
if (!res.headersSent) {
res.statusCode = 500;
res.end("Internal Server Error");
}
});

Choose a reason for hiding this comment

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

high

The current implementation for streaming static responses can be made more robust.

  1. Error Handling Order: It's safer to attach error handlers before piping the stream to the response to catch any potential synchronous errors.
  2. Client Disconnect: If a client disconnects while the file is being streamed, the read stream may continue to read the file from disk, leading to a resource leak. You should listen for the close event on the response object and destroy the file stream.
  3. Error After Headers Sent: If a stream error occurs after headers have been sent, the response cannot be changed to a 500 error. In this case, it's best to destroy the response socket to signal an error to the client.

Here is a suggested improvement that addresses these points:

  stream.on("error", (err) => {
    logger.error(
      `[milady-api] Static stream error: ${err instanceof Error ? err.message : err}`,
    );
    if (!res.headersSent) {
      res.statusCode = 500;
      res.end("Internal Server Error");
    } else {
      res.destroy();
    }
  });

  res.on("close", () => {
    stream.destroy();
  });

  stream.pipe(res);

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.

1 participant