feat(rayapp) Anyscale CLI pr0 add tailWriter with lazy double-buffer implementation#413
feat(rayapp) Anyscale CLI pr0 add tailWriter with lazy double-buffer implementation#413elliot-barn wants to merge 1 commit intomainfrom
Conversation
Extract tailWriter into its own file with a bytes.Buffer-based double-buffer design. Initial memory footprint is near zero (no upfront 1MB allocation); buffers grow lazily as data is written. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @elliot-barn, 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 introduces a new Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
The pull request introduces a tailWriter with a lazy double-buffer implementation, which is a well-designed approach for keeping a limited tail of bytes. The implementation correctly leverages bytes.Buffer's lazy growth and Reset functionality. The provided tests cover various scenarios and demonstrate the intended behavior. My main feedback concerns the handling of non-positive limits in the newTailWriter function, which could lead to unexpected behavior.
| func newTailWriter(limit int) *tailWriter { | ||
| return &tailWriter{ | ||
| limit: limit, | ||
| half: limit / 2, | ||
| } | ||
| } |
There was a problem hiding this comment.
The newTailWriter function does not validate the limit parameter. If limit is 0 or negative, the tailWriter's behavior becomes problematic. A negative limit will cause a panic in the Write method when slicing p[n-w.limit:] if n-w.limit exceeds the length of p. A limit of 0 would result in the tailWriter always returning an empty string from String() while still processing writes, which is inefficient and likely not the desired behavior. It's best to enforce a positive limit to ensure the component functions as expected and prevent runtime errors.
func newTailWriter(limit int) *tailWriter {
if limit <= 0 {
limit = 1 // Ensure a positive limit to prevent panics and ensure meaningful tailing.
}
return &tailWriter{
limit: limit,
half: limit / 2,
}
}| } | ||
| } | ||
|
|
||
| func (w *tailWriter) Write(p []byte) (int, error) { |
There was a problem hiding this comment.
maybe add a mutex? this Write is not concurrency safe, and it is going to be taking writes from both stderr and stdout at the same time I think.
| @@ -0,0 +1,72 @@ | |||
| package rayapp | |||
|
|
|||
| import "bytes" | |||
There was a problem hiding this comment.
nit: let's always use a group:
import (
"bytes"
)
Extract tailWriter into its own file with a bytes.Buffer-based double-buffer design. Initial memory footprint is near zero (no upfront 1MB allocation); buffers grow lazily as data is written.