Skip to content
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

Merged
merged 2 commits into from
Feb 6, 2025
Merged

Conversation

hiddenviewer
Copy link
Contributor

@hiddenviewer hiddenviewer commented Feb 5, 2025

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:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • Refactor
    • Streamlined the tree conversion process to enhance efficiency and reduce processing overhead.
  • Tests
    • Updated performance benchmarks for tree operations to better validate improvements in editing and conversion tasks.
    • Introduced new methods for benchmarking tree conversion at varying node sizes.

@hiddenviewer hiddenviewer self-assigned this Feb 5, 2025
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

Walkthrough

This pull request updates the Converter.swift file to improve the efficiency of the fromTreeNodes method by replacing its nested loop with a dictionary-based lookup using a depth table. Additionally, it reformats the code for enhanced readability without altering its functionality. The changes in the test suite include renaming benchmarking methods and test cases for tree editing, as well as introducing a new benchmark method for tree conversion with tests for varying node counts.

Changes

Affected Files Change Summary
Sources/API/Converter.swift Modified the fromTreeNodes method to use a depthTable dictionary for direct parent node lookup instead of a nested loop; code also reformatted for improved readability.
Tests/Benchmark/DocumentBenchmarkTests.swift Renamed methods (e.g., benchmarkTreebenchmarkTreeEdit and corresponding tests) and added a new benchmarkTreeConvert method with additional tests for different node sizes.

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
Loading
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
Loading

Poem

I'm a little rabbit, code-hopping with glee,
Depth tables guide me, as clear as can be.
I nibble on logic, efficient and neat,
With benchmarks and tests making my day complete.
A joyful hop through changes so bright,
Carrots of code fueling my delight!
🥕🐇 Happy to hop into a brighter, faster night!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 767514a and 42deb95.

📒 Files selected for processing (1)
  • Tests/Benchmark/DocumentBenchmarkTests.swift (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Tests/Benchmark/DocumentBenchmarkTests.swift
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa3dd8 and 767514a.

📒 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 to benchmarkTreeEdit 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:

  1. Replacing nested loop with a depth table dictionary
  2. Using direct parent lookup instead of iterative search
  3. Processing nodes in reverse order for better locality

Comment on lines 259 to 262
Task {
await self.benchmarkTreeConvert(10000)
exp.fulfill()
}
Copy link
Contributor

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

Comment on lines 133 to 155
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)")
}
}
Copy link
Contributor

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:

  1. Propagating the errors for better debugging, or
  2. 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.

Suggested change
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)")
}
}

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 14.47368% with 65 lines in your changes missing coverage. Please review.

Project coverage is 45.04%. Comparing base (1aa3dd8) to head (42deb95).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
Tests/Benchmark/DocumentBenchmarkTests.swift 0.00% 65 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@humdrum humdrum left a 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.

@hiddenviewer hiddenviewer merged commit cbac07b into main Feb 6, 2025
3 checks passed
@hiddenviewer hiddenviewer deleted the apply_v0.4.28 branch February 6, 2025 02:42
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.

2 participants