-
Notifications
You must be signed in to change notification settings - Fork 4
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
Apply updates from yorkie-js-sdk v0.4.28 #193
Conversation
WalkthroughThis pull request updates the Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Converter as Converter
participant DepthTable as DepthTable
Client->>Converter: Call fromTreeNodes(nodes)
loop For each node in reverse order
Converter->>DepthTable: Retrieve parent node using current depth
DepthTable-->>Converter: Return corresponding parent node
end
Converter-->>Client: Return tree with assigned parent nodes
sequenceDiagram
participant TR as Test Runner
participant DBTests as DocumentBenchmarkTests
participant Benchmark as Benchmark Method
TR->>DBTests: Execute testDocumentTreeEdit/Convert methods
DBTests->>Benchmark: Call benchmarkTreeEdit or benchmarkTreeConvert with size parameter
Benchmark-->>DBTests: Return performance result
DBTests-->>TR: Report test completion
Poem
Tip 🌐 Web search-backed reviews and chat
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
Tests/Benchmark/DocumentBenchmarkTests.swift (1)
255-292
: Consider adjusting timeouts based on node count.The timeout is fixed at 20 seconds for all test sizes. Consider scaling the timeout with the node count to accommodate larger trees.
func testDocumentTreeConvert10000() throws { self.measure { let exp = expectation(description: "measure") Task { await self.benchmarkTreeConvert(10000) exp.fulfill() } - wait(for: [exp], timeout: 20) + wait(for: [exp], timeout: 10) } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
Sources/API/Converter.swift
(1 hunks)Tests/Benchmark/DocumentBenchmarkTests.swift
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build
- GitHub Check: build
🔇 Additional comments (2)
Tests/Benchmark/DocumentBenchmarkTests.swift (1)
21-38
: Great renaming for improved clarity!The renaming of
benchmarkTree
tobenchmarkTreeEdit
and corresponding test methods better reflects their purpose of benchmarking tree editing operations.Also applies to: 157-183
Sources/API/Converter.swift (1)
986-998
: Excellent optimization of tree node conversion!The new implementation improves efficiency by:
- Replacing nested loop with a depth table dictionary
- Using direct parent lookup instead of iterative search
- Processing nodes in reverse order for better locality
Task { | ||
await self.benchmarkTreeConvert(10000) | ||
exp.fulfill() | ||
} |
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.
🛠️ Refactor suggestion
Add @mainactor annotation for consistency.
Other test methods use @MainActor
for their task blocks, but it's missing in the new test methods.
-Task {
+Task { @MainActor in
await self.benchmarkTreeConvert(10000)
exp.fulfill()
}
Also applies to: 272-275, 285-288
func benchmarkTreeConvert(_ size: Int) async { | ||
let doc = Document(key: "test-doc") | ||
|
||
do { | ||
try await doc.update { root, _ in | ||
var children: [JSONTreeTextNode] = [] | ||
for _ in 1 ... size { | ||
children.append(JSONTreeTextNode(value: "a")) | ||
} | ||
|
||
root.tree = JSONTree(initialRoot: | ||
JSONTreeElementNode(type: "doc", | ||
children: [JSONTreeElementNode(type: "p", children: children)]) | ||
) | ||
} | ||
|
||
let root = try await(doc.getRoot().tree as? JSONTree)?.getIndexTree().root | ||
let pbTreeNodes = Converter.toTreeNodes(root) | ||
_ = try Converter.fromTreeNodes(pbTreeNodes) | ||
} catch { | ||
XCTAssert(false, "\(error)") | ||
} | ||
} |
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.
🛠️ Refactor suggestion
Add error handling for conversion failures.
While the benchmark method is well-structured, it silently fails on conversion errors. Consider either:
- Propagating the errors for better debugging, or
- Adding assertions to verify successful conversion.
func benchmarkTreeConvert(_ size: Int) async {
let doc = Document(key: "test-doc")
do {
try await doc.update { root, _ in
var children: [JSONTreeTextNode] = []
for _ in 1 ... size {
children.append(JSONTreeTextNode(value: "a"))
}
root.tree = JSONTree(initialRoot:
JSONTreeElementNode(type: "doc",
children: [JSONTreeElementNode(type: "p", children: children)])
)
}
let root = try await(doc.getRoot().tree as? JSONTree)?.getIndexTree().root
let pbTreeNodes = Converter.toTreeNodes(root)
- _ = try Converter.fromTreeNodes(pbTreeNodes)
+ let convertedTree = try Converter.fromTreeNodes(pbTreeNodes)
+ XCTAssertNotNil(convertedTree, "Tree conversion failed")
} catch {
- XCTAssert(false, "\(error)")
+ XCTFail("Benchmark failed with error: \(error)")
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func benchmarkTreeConvert(_ size: Int) async { | |
let doc = Document(key: "test-doc") | |
do { | |
try await doc.update { root, _ in | |
var children: [JSONTreeTextNode] = [] | |
for _ in 1 ... size { | |
children.append(JSONTreeTextNode(value: "a")) | |
} | |
root.tree = JSONTree(initialRoot: | |
JSONTreeElementNode(type: "doc", | |
children: [JSONTreeElementNode(type: "p", children: children)]) | |
) | |
} | |
let root = try await(doc.getRoot().tree as? JSONTree)?.getIndexTree().root | |
let pbTreeNodes = Converter.toTreeNodes(root) | |
_ = try Converter.fromTreeNodes(pbTreeNodes) | |
} catch { | |
XCTAssert(false, "\(error)") | |
} | |
} | |
func benchmarkTreeConvert(_ size: Int) async { | |
let doc = Document(key: "test-doc") | |
do { | |
try await doc.update { root, _ in | |
var children: [JSONTreeTextNode] = [] | |
for _ in 1 ... size { | |
children.append(JSONTreeTextNode(value: "a")) | |
} | |
root.tree = JSONTree(initialRoot: | |
JSONTreeElementNode(type: "doc", | |
children: [JSONTreeElementNode(type: "p", children: children)]) | |
) | |
} | |
let root = try await(doc.getRoot().tree as? JSONTree)?.getIndexTree().root | |
let pbTreeNodes = Converter.toTreeNodes(root) | |
let convertedTree = try Converter.fromTreeNodes(pbTreeNodes) | |
XCTAssertNotNil(convertedTree, "Tree conversion failed") | |
} catch { | |
XCTFail("Benchmark failed with error: \(error)") | |
} | |
} |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #193 +/- ##
==========================================
- Coverage 45.14% 45.04% -0.10%
==========================================
Files 109 109
Lines 27190 27250 +60
==========================================
Hits 12276 12276
- Misses 14914 14974 +60 ☔ View full report in Codecov by Sentry. |
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.
Wow! It's 10 times faster.
What this PR does / why we need it:
Applied changes from https://github.com/yorkie-team/yorkie-js-sdk/releases/tag/v0.4.28
Which issue(s) this PR fixes:
Applied
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit