Repository navigation
Conversation
… and connections For these inputs both functions copy the file with the internal `read.graph.toraw()`, which grew its result with `c()` once per 20000-byte chunk. Each `c()` copies everything read so far, so the copy took quadratic time in the file size. Collect the chunks in a list and call `unlist()` once. The `readBin()` calls and the stop condition are unchanged, so the result is the same. Add tests for chunk boundaries and for `~` paths and connections.
This branch has not been deployed
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.
When the path contains
~or://, orfileis a connection,read_graph()andwrite_graph()copy the file with the internalread.graph.toraw(), as domax_cliques(file = )andgraph_from_graphdb(). That function grew its result withc()once per 20000-byte chunk. Eachc()copies everything read so far, so the copy took quadratic time in the file size.This PR collects the chunks in a list and calls
unlist()once. ThereadBin()calls and the stop condition are unchanged, so the result is the same; an empty file still givesraw(0).Timings for a 32.8 MB GraphML file (Windows 11, R 4.6.2, median of 5 runs, main and this PR alternating, fresh
Rscripteach):read.graph.toraw()aloneread_graph("<dir>/g~.graphml", "graphml")write_graph(g, "<dir>/out~.graphml", "graphml")read_graph("<dir>/g.graphml", "graphml"), controlThe copy speedup is 24x at 2 MB and 85x at 8 MB.
New tests in
test-foreign.Rread files of 0 to 123457 bytes through a path and through file and raw connections, and check that~paths and connections give the same graphs and files as a plain path. They also pass on main. The full test suite passes on both, andair formatchanges nothing.Worked with Claude to write and test the patch for this issue.