-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Add Windows compatibility by replacing renameio with natefinch/atomic #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
soaringjerry
wants to merge
2
commits into
coder:main
Choose a base branch
from
soaringjerry:fix-windows-compatibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+17
−11
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to maintain the performance characteristics of the previous approach (mainly, not buffering the whole structure in memory), we should
g.export
into aBufWriter
that leads into anio.Pipe
. We'd then pass the reader of that pipe intoatomic.WriteFile
. Then we only pay the (constant) memory cost of the BufWriter. The Pipe code is a bit annoying but the compat is worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ammario,
Thank you so much for taking the time to review this and for the excellent suggestion! That's a very insightful point about the potential memory overhead of buffering the entire graph before writing.
Your proposed solution using io.Pipe to create a streaming write is indeed a more elegant and memory-efficient approach in theory. I really appreciate you pointing this out.
I'm currently running some benchmarks to compare the performance characteristics and actual memory usage of two approaches:
The current implementation (buffering in memory).
Your suggested implementation (using io.Pipe).
I want to ensure the final solution is not only cross-platform palavras-chave but also as performant and memory-efficient as the original renameio implementation.
I will post my findings here shortly. Thanks again for the great feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The level of LLM in this contribution is nearly overwhelming
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ammario,
I deeply leverage LLMs in my work to enhance both efficiency and quality. I'm experimenting with integrating my AI workflow approaches into projects (you can see Dreamhub and PCAS on my profile, though they're still in exploration phase), and these attempts have helped me achieve some nice productivity improvements.
I ran comprehensive benchmarks and found some interesting results:
For memory efficiency, the io.Pipe implementation performs excellently, achieving 50-65% memory savings across all test scales. Particularly with 50,000 nodes, it saves 128.2 MB of memory.
There's a clear performance trade-off: while single operations are 22-64% slower, surprisingly, io.Pipe actually performs 5.5% better in concurrent scenarios - likely due to reduced memory contention.
Based on this data, I believe both implementations have their place. For large-scale graph data or memory-constrained environments, io.Pipe's memory efficiency is worthwhile; for small datasets and latency-sensitive applications, the original Buffer implementation might be more suitable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should do one thing and do it well, which is adding Windows compatibility to the export function. I don't really care about the +/- 20%, there is an expectation (on consumers) that throughput could vary like that between versions. It's far more severe to double the peak memory usage, esp. when these structures are designed to get quite large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ammario
I understand your perspective on memory usage. However, performance is critical for my use case - the 22-64% performance degradation would significantly impact my system's responsiveness.
I'll try to implement the io.Pipe approach for this PR when I have time, as I understand memory efficiency is your priority for the project. Meanwhile, I'll maintain the buffer-based implementation in my own fork since it better suits my performance requirements.
Thanks for the feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be a happy medium where both memory and throughput could be preserved. One concept is to use a bufio.Writer and bufio.Reader on both sides of the pipe. Since bufio.Reader implements WriteTo,
io.Copy
withinatomic.WriteFile
won't have to allocate a copy buf or do any memory shuffling. A lot of the new overhead withio.Pipe
is due to synchronization which smart buffering should mostly alleviate.