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

Optimize max VersionVector in ApplyChanges to improve memory efficiency #1164

Merged
merged 4 commits into from
Feb 25, 2025

Conversation

raararaara
Copy link
Contributor

@raararaara raararaara commented Feb 20, 2025

What this PR does / why we need it:
This PR serves as a follow-up to the previous PR #1153. It optimizes the max version vector in a manner similar to the optimization applied to the min version vector.

During the process of applying remote changes with ApplyChanges, the version vector was being updated each time. This resulted in unnecessary copy creation of the parameters passed to the Max method. By modifying the function to directly modify the object within instead of creating copies, we enhance memory efficiency.

Any background context you want to provide?

Which issue(s) this PR fixes:

Fixes #1152

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Addressed and resolved all CodeRabbit review comments
  • Didn't break anything

Summary by CodeRabbit

  • Refactor

    • Improved error handling for change identifier generation, ensuring fresh instances are returned in error scenarios.
    • Updated the initialization process for change identifiers in document structures for better clarity and structure.
    • Modified version vector methods to accept pointers, enhancing memory efficiency and streamlining comparisons.
  • Tests

    • Adjusted test cases to utilize pointers for version vector comparisons, ensuring consistency with the updated method implementations.

Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

The pull request modifies the handling of change IDs and version vectors across multiple components. The fromChangeID function now returns a newly constructed change ID with detailed initial values instead of a static default when errors occur. Additionally, methods in the change and document packages, as well as test helpers, have been updated to use dynamic change ID instantiation. The version vector operations are refined by switching from value to pointer parameters, with the Min and Max methods now modifying the existing vector in place.

Changes

File(s) Summary of Changes
api/converter/from_pb.go, pkg/document/internal_document.go, test/helper/helper.go Updated change ID initialization and error handling. The functions now construct a new change.ID using detailed initial values (client/server sequences, lamport, actor, version vector) instead of returning a static initial value.
pkg/document/change/id.go, pkg/document/time/version_vector.go Modified version vector operations to use pointer parameters. The Max and Min methods now accept pointers and dereference them for in-place updates, while callers pass version vectors by reference.
pkg/document/time/version_vector_test.go, server/backend/database/memory/database.go, server/backend/database/mongo/client.go Updated tests and database methods to call Min with pointers to version vectors instead of values.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Converter
    participant IDFactory
    Caller->>Converter: Call fromChangeID(pbChange)
    alt Extraction succeeds
        Converter->>Caller: Return valid change.ID
    else Extraction fails
        Converter->>IDFactory: Construct new change.ID with initial values
        IDFactory-->>Converter: Return detailed change.ID
        Converter->>Caller: Return detailed change.ID
    end
Loading

Possibly related PRs

  • Preserve Detached Client's Lamport in Version Vector #1090: The changes in the main PR, which enhance error handling in the fromChangeID function, are related to the modifications in the retrieved PR that involve the handling of version vectors and the use of change.InitialID(), as both PRs address the initialization and management of change.ID instances.
  • Add minLamport for proper GC of deactivated clients #1060: The changes in the main PR are related to the modifications in the pkg/document/time/version_vector.go file, specifically the updates to the Min and Max methods that now accept pointers, which aligns with the changes in the retrieved PR that also modifies the Min method to accept a pointer.
  • Improve Version Vector Handling for Legacy SDK and Snapshots #1096: The changes in the main PR are related to the modifications in the pkg/document/change/id.go file, specifically regarding the handling of change.InitialID() which aligns with the updates made in the retrieved PR that also involves changes to the ID struct in the same file.

Suggested reviewers

  • hackerwins
  • chacha912

📜 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 7fcea41 and 90a0c9c.

📒 Files selected for processing (1)
  • pkg/document/time/version_vector_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/document/time/version_vector_test.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: complex-test
  • GitHub Check: bench

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

@hackerwins-yorkie hackerwins-yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark Analysis 📊

This is a comparison result between the previous(e687d61) and the current commit(7bbe9e5).

Significant Changes (≥20% difference)

Benchmark suite Previous Current Change
BenchmarkVersionVector/clients_1000/ (B/op) 22.07 GB 6.58 GB 🟢 -70.16%
BenchmarkVersionVector/clients_1000/ (4_attach(ms)) 249.00 ms 104.00 ms 🟢 -58.23%
BenchmarkSync/memory_sync_10000_test/ (ns/op) 7.47 ms 10.05 ms 🔴 +34.52%
BenchmarkVersionVector/clients_1000/ (ns/op) 60.97 s 48.76 s 🟢 -20.03%

Key Observations 🔍

  • Significant improvements were observed in the BenchmarkVersionVector/clients_1000/ suite, with a notable decrease in memory usage (B/op) by 70.16% and a significant improvement in attachment speed (4_attach(ms)) by 58.23%.
  • The BenchmarkSync/memory_sync_10000_test/ suite showed a significant increase in operation time (ns/op) by 34.52%, indicating a performance degradation in memory synchronization.
  • Overall, several benchmarks across different suites showcased slight performance improvements or stability, with some minor fluctuations in speed and memory usage.

Since no other significant changes (≥20% difference) were observed in the remaining benchmark suites, the focus should be on optimizing memory synchronization to reverse the performance degradation trend noted.

Clock Analysis

Lamport (v0.5.2)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 84.96 ms 793.94 ms 34,794.80 ms
Memory Allocations 35.11 MB 219.92 MB 4.91 GB
Number of Allocations (allocs/op) 69,271 1,246,728 81,485,288
ChangePack Size 138.0 B 137.0 B 141.0 B
Snapshot Size 379.0 B 3.08 KB 30.08 KB
Push-Pull Time 2.0 ms 1.5 ms 4.0 ms
Attach Time 4.5 ms 11.0 ms 31.0 ms
ChangePack After Detach 138.0 B 140.0 B 141.0 B
Snapshot After Detach 136.0 B 137.0 B 139.0 B
Push-Pull After Detach 2.5 ms 5.0 ms 9.5 ms

VV (current)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 171.98 ms 1.50 s 48.76 s
Memory Allocations 20.94 MB 217.05 MB 6.58 GB
Number of Allocations (allocs/op) 83,378 1,484,440 93,477,305
ChangePack Size 745.00 B 6.14 KB 60.16 KB
Snapshot Size 379.00 B 3.08 KB 30.08 KB
Push-Pull Time 8.00 ms 12.00 ms 96.00 ms
Attach Time 6.00 ms 10.00 ms 104.00 ms
ChangePack After Detach 805.00 B 6.21 KB 60.22 KB
Snapshot After Detach 136.00 B 137.00 B 139.00 B
Push-Pull After Detach 8.00 ms 10.00 ms 24.00 ms

Summary

  • Total operation time increases significantly with Version Vector compared to Lamport across all client scenarios.
  • Version Vector requires more memory allocations for all client scenarios than Lamport.
  • The ChangePack size and Snapshot size are larger in Version Vector compared to Lamport.
  • Push-Pull Time is higher for Version Vector as the number of clients increase, indicating potential scalability issues.
  • Version Vector shows faster Attach Time for 1000 clients compared to Lamport.
  • Version Vector shows improvements in ChangePack After Detach, Snapshot After Detach, and Push-Pull After Detach timings compared to Lamport, especially for 1000 clients, showcasing potential efficiency gains.

Detailed Test Results

BenchmarkDocument
Benchmark suite Previous Current Change
constructor_test/ (ns/op) 1439.00 ns 1486.00 ns 🔴 +3.27%
constructor_test/ (B/op) 1.39 KB 1.43 KB 🔴 +3.47%
constructor_test/ (allocs/op) 24 allocs 25 allocs 🔴 +4.17%
status_test/ (ns/op) 1028.00 ns 1103.00 ns 🔴 +7.30%
status_test/ (B/op) 1.35 KB 1.40 KB 🔴 +3.55%
status_test/ (allocs/op) 22 allocs 23 allocs 🔴 +4.55%
equals_test/ (ns/op) 7864.00 ns 7973.00 ns 🔴 +1.39%
equals_test/ (B/op) 7.56 KB 7.71 KB 🔴 +1.90%
equals_test/ (allocs/op) 129 allocs 132 allocs 🔴 +2.33%
nested_update_test/ (ns/op) 17079.00 ns 17149.00 ns 🔴 +0.41%
nested_update_test/ (B/op) 12.31 KB 12.36 KB 🔴 +0.39%
nested_update_test/ (allocs/op) 258 allocs 259 allocs 🔴 +0.39%
delete_test/ (ns/op) 27313.00 ns 27473.00 ns 🔴 +0.59%
delete_test/ (B/op) 15.79 KB 15.84 KB 🔴 +0.30%
delete_test/ (allocs/op) 339 allocs 340 allocs 🔴 +0.29%
object_test/ (ns/op) 8546.00 ns 8773.00 ns 🔴 +2.66%
object_test/ (B/op) 7.03 KB 7.08 KB 🔴 +0.68%
object_test/ (allocs/op) 118 allocs 119 allocs 🔴 +0.85%
array_test/ (ns/op) 28984.00 ns 29377.00 ns 🔴 +1.36%
array_test/ (B/op) 12.14 KB 12.19 KB 🔴 +0.40%
array_test/ (allocs/op) 273 allocs 274 allocs 🔴 +0.37%
text_test/ (ns/op) 32155.00 ns 32734.00 ns 🔴 +1.80%
text_test/ (B/op) 15.19 KB 15.24 KB 🔴 +0.32%
text_test/ (allocs/op) 484 allocs 485 allocs 🔴 +0.21%
text_composition_test/ (ns/op) 31674.00 ns 32376.00 ns 🔴 +2.22%
text_composition_test/ (B/op) 18.70 KB 18.75 KB 🔴 +0.26%
text_composition_test/ (allocs/op) 501 allocs 502 allocs 🔴 +0.20%
rich_text_test/ (ns/op) 87424.00 ns 88340.00 ns 🔴 +1.05%
rich_text_test/ (B/op) 39.36 KB 39.41 KB 🔴 +0.13%
rich_text_test/ (allocs/op) 1,146 allocs 1,147 allocs 🔴 +0.09%
counter_test/ (ns/op) 18201.00 ns 18406.00 ns 🔴 +1.13%
counter_test/ (B/op) 11.81 KB 11.86 KB 🔴 +0.40%
counter_test/ (allocs/op) 253 allocs 254 allocs 🔴 +0.40%
text_edit_gc_100/ (ns/op) 1.39 ms 1.44 ms 🔴 +3.29%
text_edit_gc_100/ (B/op) 864.90 KB 864.95 KB ⚪ 0%
text_edit_gc_100/ (allocs/op) 17,281 allocs 17,283 allocs 🔴 +0.01%
text_edit_gc_1000/ (ns/op) 53.39 ms 55.60 ms 🔴 +4.14%
text_edit_gc_1000/ (B/op) 46.84 MB 46.84 MB ⚪ 0%
text_edit_gc_1000/ (allocs/op) 185,598 allocs 185,598 allocs ⚪ 0%
text_split_gc_100/ (ns/op) 2.12 ms 2.21 ms 🔴 +4.12%
text_split_gc_100/ (B/op) 1.58 MB 1.58 MB ⚪ 0%
text_split_gc_100/ (allocs/op) 15,950 allocs 15,952 allocs 🔴 +0.01%
text_split_gc_1000/ (ns/op) 128.25 ms 134.42 ms 🔴 +4.82%
text_split_gc_1000/ (B/op) 137.79 MB 137.79 MB ⚪ 0%
text_split_gc_1000/ (allocs/op) 185,000 allocs 184,999 allocs ⚪ 0%
text_delete_all_10000/ (ns/op) 18.43 ms 20.27 ms 🔴 +9.99%
text_delete_all_10000/ (B/op) 10.58 MB 10.58 MB ⚪ 0%
text_delete_all_10000/ (allocs/op) 56,134 allocs 56,133 allocs ⚪ 0%
text_delete_all_100000/ (ns/op) 312.31 ms 308.88 ms 🟢 -1.10%
text_delete_all_100000/ (B/op) 105.54 MB 105.56 MB 🔴 +0.02%
text_delete_all_100000/ (allocs/op) 566,133 allocs 566,179 allocs ⚪ 0%
text_100/ (ns/op) 234634.00 ns 233173.00 ns 🟢 -0.62%
text_100/ (B/op) 120.94 KB 120.99 KB 🔴 +0.04%
text_100/ (allocs/op) 5,181 allocs 5,182 allocs 🔴 +0.02%
text_1000/ (ns/op) 2.46 ms 2.49 ms 🔴 +0.93%
text_1000/ (B/op) 1.16 MB 1.16 MB ⚪ 0%
text_1000/ (allocs/op) 51,084 allocs 51,085 allocs ⚪ 0%
array_1000/ (ns/op) 1.24 ms 1.25 ms 🔴 +0.92%
array_1000/ (B/op) 1.09 MB 1.09 MB ⚪ 0%
array_1000/ (allocs/op) 11,879 allocs 11,880 allocs ⚪ 0%
array_10000/ (ns/op) 13.33 ms 13.78 ms 🔴 +3.33%
array_10000/ (B/op) 9.89 MB 9.89 MB 🟢 -0.01%
array_10000/ (allocs/op) 120,735 allocs 120,731 allocs ⚪ 0%
array_gc_100/ (ns/op) 131750.00 ns 133656.00 ns 🔴 +1.45%
array_gc_100/ (B/op) 99.89 KB 99.93 KB 🔴 +0.04%
array_gc_100/ (allocs/op) 1,266 allocs 1,267 allocs 🔴 +0.08%
array_gc_1000/ (ns/op) 1.42 ms 1.45 ms 🔴 +1.93%
array_gc_1000/ (B/op) 1.14 MB 1.14 MB ⚪ 0%
array_gc_1000/ (allocs/op) 12,926 allocs 12,927 allocs ⚪ 0%
counter_1000/ (ns/op) 202098.00 ns 203733.00 ns 🔴 +0.81%
counter_1000/ (B/op) 178.13 KB 178.19 KB 🔴 +0.03%
counter_1000/ (allocs/op) 5,771 allocs 5,772 allocs 🔴 +0.02%
counter_10000/ (ns/op) 2.17 ms 2.18 ms 🔴 +0.51%
counter_10000/ (B/op) 2.07 MB 2.07 MB ⚪ 0%
counter_10000/ (allocs/op) 59,778 allocs 59,779 allocs ⚪ 0%
object_1000/ (ns/op) 1.39 ms 1.43 ms 🔴 +2.61%
object_1000/ (B/op) 1.44 MB 1.44 MB 🔴 +0.02%
object_1000/ (allocs/op) 9,925 allocs 9,926 allocs 🔴 +0.01%
object_10000/ (ns/op) 14.82 ms 15.40 ms 🔴 +3.91%
object_10000/ (B/op) 12.35 MB 12.35 MB 🟢 -0.02%
object_10000/ (allocs/op) 101,232 allocs 101,225 allocs ⚪ 0%
tree_100/ (ns/op) 1.02 ms 1.06 ms 🔴 +3.35%
tree_100/ (B/op) 951.02 KB 951.08 KB ⚪ 0%
tree_100/ (allocs/op) 6,102 allocs 6,103 allocs 🔴 +0.02%
tree_1000/ (ns/op) 74.23 ms 78.64 ms 🔴 +5.94%
tree_1000/ (B/op) 86.58 MB 86.58 MB ⚪ 0%
tree_1000/ (allocs/op) 60,111 allocs 60,113 allocs ⚪ 0%
tree_10000/ (ns/op) 9.68 s 10.14 s 🔴 +4.80%
tree_10000/ (B/op) 8.58 GB 8.58 GB ⚪ 0%
tree_10000/ (allocs/op) 600,173 allocs 600,182 allocs ⚪ 0%
tree_delete_all_1000/ (ns/op) 78.41 ms 80.94 ms 🔴 +3.24%
tree_delete_all_1000/ (B/op) 87.57 MB 87.57 MB ⚪ 0%
tree_delete_all_1000/ (allocs/op) 75,289 allocs 75,288 allocs ⚪ 0%
tree_edit_gc_100/ (ns/op) 3.96 ms 3.91 ms 🟢 -1.30%
tree_edit_gc_100/ (B/op) 4.15 MB 4.15 MB ⚪ 0%
tree_edit_gc_100/ (allocs/op) 15,147 allocs 15,148 allocs ⚪ 0%
tree_edit_gc_1000/ (ns/op) 332.75 ms 327.94 ms 🟢 -1.44%
tree_edit_gc_1000/ (B/op) 384.04 MB 384.04 MB ⚪ 0%
tree_edit_gc_1000/ (allocs/op) 154,952 allocs 154,952 allocs ⚪ 0%
tree_split_gc_100/ (ns/op) 2.67 ms 2.68 ms 🔴 +0.29%
tree_split_gc_100/ (B/op) 2.41 MB 2.41 MB ⚪ 0%
tree_split_gc_100/ (allocs/op) 11,131 allocs 11,132 allocs ⚪ 0%
tree_split_gc_1000/ (ns/op) 197.74 ms 198.46 ms 🔴 +0.36%
tree_split_gc_1000/ (B/op) 222.50 MB 222.50 MB ⚪ 0%
tree_split_gc_1000/ (allocs/op) 122,053 allocs 122,068 allocs 🔴 +0.01%
BenchmarkRPC
Benchmark suite Previous Current Change
client_to_server/ (ns/op) 431.85 ms 426.93 ms 🟢 -1.14%
client_to_server/ (B/op) 16.13 MB 16.11 MB 🟢 -0.15%
client_to_server/ (allocs/op) 223,674 allocs 223,151 allocs 🟢 -0.23%
client_to_client_via_server/ (ns/op) 788.62 ms 809.03 ms 🔴 +2.59%
client_to_client_via_server/ (B/op) 37.20 MB 38.12 MB 🔴 +2.48%
client_to_client_via_server/ (allocs/op) 478,656 allocs 484,535 allocs 🔴 +1.23%
attach_large_document/ (ns/op) 1.32 s 1.23 s 🟢 -7.13%
attach_large_document/ (B/op) 1.89 GB 1.90 GB 🔴 +0.44%
attach_large_document/ (allocs/op) 12,321 allocs 12,418 allocs 🔴 +0.79%
adminCli_to_server/ (ns/op) 542.08 ms 541.25 ms 🟢 -0.15%
adminCli_to_server/ (B/op) 21.76 MB 20.38 MB 🟢 -6.33%
adminCli_to_server/ (allocs/op) 291,952 allocs 291,953 allocs ⚪ 0%
BenchmarkLocker
Benchmark suite Previous Current Change
(ns/op) 82.86 ns 82.48 ns 🟢 -0.46%
(B/op) 32.00 B 32.00 B ⚪ 0%
(allocs/op) 1 allocs 1 allocs ⚪ 0%
BenchmarkLockerParallel
Benchmark suite Previous Current Change
(ns/op) 45.80 ns 45.15 ns 🟢 -1.42%
(B/op) 0.00 B 0.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkLockerMoreKeys
Benchmark suite Previous Current Change
(ns/op) 180.50 ns 177.10 ns 🟢 -1.88%
(B/op) 31.00 B 31.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkRWLocker
Benchmark suite Previous Current Change
RWLock_rate_2/ (ns/op) 50.25 ns 49.43 ns 🟢 -1.63%
RWLock_rate_2/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_2/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_10/ (ns/op) 44.88 ns 44.25 ns 🟢 -1.40%
RWLock_rate_10/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_10/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_100/ (ns/op) 63.08 ns 59.33 ns 🟢 -5.94%
RWLock_rate_100/ (B/op) 2.00 B 2.00 B ⚪ 0%
RWLock_rate_100/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_1000/ (ns/op) 91.91 ns 88.96 ns 🟢 -3.21%
RWLock_rate_1000/ (B/op) 8.00 B 8.00 B ⚪ 0%
RWLock_rate_1000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkChange
Benchmark suite Previous Current Change
Push_10_Changes/ (ns/op) 4.54 ms 4.59 ms 🔴 +1.21%
Push_10_Changes/ (B/op) 150.42 KB 150.21 KB 🟢 -0.14%
Push_10_Changes/ (allocs/op) 1,623 allocs 1,616 allocs 🟢 -0.43%
Push_100_Changes/ (ns/op) 16.52 ms 16.71 ms 🔴 +1.15%
Push_100_Changes/ (B/op) 770.59 KB 776.69 KB 🔴 +0.79%
Push_100_Changes/ (allocs/op) 8,509 allocs 8,504 allocs 🟢 -0.06%
Push_1000_Changes/ (ns/op) 129.20 ms 132.48 ms 🔴 +2.54%
Push_1000_Changes/ (B/op) 7.22 MB 7.30 MB 🔴 +1.07%
Push_1000_Changes/ (allocs/op) 79,325 allocs 79,323 allocs ⚪ 0%
Pull_10_Changes/ (ns/op) 3.70 ms 3.79 ms 🔴 +2.26%
Pull_10_Changes/ (B/op) 124.59 KB 124.01 KB 🟢 -0.46%
Pull_10_Changes/ (allocs/op) 1,456 allocs 1,456 allocs ⚪ 0%
Pull_100_Changes/ (ns/op) 5.32 ms 5.49 ms 🔴 +3.09%
Pull_100_Changes/ (B/op) 354.61 KB 353.01 KB 🟢 -0.45%
Pull_100_Changes/ (allocs/op) 5,182 allocs 5,181 allocs 🟢 -0.02%
Pull_1000_Changes/ (ns/op) 10.88 ms 11.58 ms 🔴 +6.45%
Pull_1000_Changes/ (B/op) 2.20 MB 2.20 MB 🟢 -0.10%
Pull_1000_Changes/ (allocs/op) 44,681 allocs 44,681 allocs ⚪ 0%
BenchmarkSnapshot
Benchmark suite Previous Current Change
Push_3KB_snapshot/ (ns/op) 19.55 ms 19.21 ms 🟢 -1.78%
Push_3KB_snapshot/ (B/op) 905.58 KB 903.03 KB 🟢 -0.28%
Push_3KB_snapshot/ (allocs/op) 8,516 allocs 8,515 allocs 🟢 -0.01%
Push_30KB_snapshot/ (ns/op) 132.18 ms 135.90 ms 🔴 +2.82%
Push_30KB_snapshot/ (B/op) 8.24 MB 8.10 MB 🟢 -1.73%
Push_30KB_snapshot/ (allocs/op) 89,008 allocs 89,229 allocs 🔴 +0.25%
Pull_3KB_snapshot/ (ns/op) 7.80 ms 7.61 ms 🟢 -2.44%
Pull_3KB_snapshot/ (B/op) 1.12 MB 1.06 MB 🟢 -5.06%
Pull_3KB_snapshot/ (allocs/op) 20,064 allocs 19,257 allocs 🟢 -4.02%
Pull_30KB_snapshot/ (ns/op) 19.91 ms 20.44 ms 🔴 +2.64%
Pull_30KB_snapshot/ (B/op) 9.31 MB 8.77 MB 🟢 -5.83%
Pull_30KB_snapshot/ (allocs/op) 193,610 allocs 185,677 allocs 🟢 -4.10%
BenchmarkSplayTree
Benchmark suite Previous Current Change
stress_test_100000/ (ns/op) 0.19 ns 0.19 ns 🟢 -3.15%
stress_test_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_200000/ (ns/op) 0.40 ns 0.38 ns 🟢 -3.75%
stress_test_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_300000/ (ns/op) 0.57 ns 0.58 ns 🔴 +1.50%
stress_test_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_100000/ (ns/op) 0.01 ns 0.01 ns 🔴 +5.51%
random_access_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_200000/ (ns/op) 0.03 ns 0.03 ns 🔴 +5.75%
random_access_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_300000/ (ns/op) 0.04 ns 0.05 ns 🔴 +7.78%
random_access_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
editing_trace_bench/ (ns/op) 0.00 ns 0.00 ns 🔴 +19.08%
editing_trace_bench/ (B/op) 0.00 B 0.00 B ⚪ 0%
editing_trace_bench/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkSync
Benchmark suite Previous Current Change
memory_sync_10_test/ (ns/op) 7288.00 ns 7332.00 ns 🔴 +0.60%
memory_sync_10_test/ (B/op) 1.34 KB 1.34 KB ⚪ 0%
memory_sync_10_test/ (allocs/op) 35 allocs 35 allocs ⚪ 0%
memory_sync_100_test/ (ns/op) 55353.00 ns 57178.00 ns 🔴 +3.30%
memory_sync_100_test/ (B/op) 9.51 KB 9.50 KB 🟢 -0.04%
memory_sync_100_test/ (allocs/op) 268 allocs 268 allocs ⚪ 0%
memory_sync_1000_test/ (ns/op) 616285.00 ns 628491.00 ns 🔴 +1.98%
memory_sync_1000_test/ (B/op) 75.92 KB 75.70 KB 🟢 -0.29%
memory_sync_1000_test/ (allocs/op) 2,111 allocs 2,105 allocs 🟢 -0.28%
memory_sync_10000_test/ (ns/op) 7.47 ms 10.05 ms 🔴 +34.52%
memory_sync_10000_test/ (B/op) 761.49 KB 762.59 KB 🔴 +0.14%
memory_sync_10000_test/ (allocs/op) 20,475 allocs 20,515 allocs 🔴 +0.20%
BenchmarkTextEditing
Benchmark suite Previous Current Change
(ns/op) 5.18 s 5.39 s 🔴 +3.97%
(B/op) 3.92 GB 3.92 GB ⚪ 0%
(allocs/op) 20,619,777 allocs 20,619,832 allocs ⚪ 0%
BenchmarkTree
Benchmark suite Previous Current Change
10000_vertices_to_protobuf/ (ns/op) 4.17 ms 4.68 ms 🔴 +12.19%
10000_vertices_to_protobuf/ (B/op) 6.36 MB 6.36 MB ⚪ 0%
10000_vertices_to_protobuf/ (allocs/op) 70,025 allocs 70,025 allocs ⚪ 0%
10000_vertices_from_protobuf/ (ns/op) 217.30 ms 239.31 ms 🔴 +10.13%
10000_vertices_from_protobuf/ (B/op) 442.30 MB 442.31 MB ⚪ 0%
10000_vertices_from_protobuf/ (allocs/op) 290,038 allocs 290,039 allocs ⚪ 0%
20000_vertices_to_protobuf/ (ns/op) 8.84 ms 9.45 ms 🔴 +6.91%
20000_vertices_to_protobuf/ (B/op) 12.89 MB 12.89 MB ⚪ 0%
20000_vertices_to_protobuf/ (allocs/op) 140,028 allocs 140,028 allocs ⚪ 0%
20000_vertices_from_protobuf/ (ns/op) 884.61 ms 903.91 ms 🔴 +2.18%
20000_vertices_from_protobuf/ (B/op) 1.70 GB 1.70 GB ⚪ 0%
20000_vertices_from_protobuf/ (allocs/op) 580,043 allocs 580,050 allocs ⚪ 0%
30000_vertices_to_protobuf/ (ns/op) 14.26 ms 14.76 ms 🔴 +3.50%
30000_vertices_to_protobuf/ (B/op) 18.98 MB 18.98 MB ⚪ 0%
30000_vertices_to_protobuf/ (allocs/op) 210,029 allocs 210,030 allocs ⚪ 0%
30000_vertices_from_protobuf/ (ns/op) 2.00 s 2.05 s 🔴 +2.63%
30000_vertices_from_protobuf/ (B/op) 3.75 GB 3.75 GB ⚪ 0%
30000_vertices_from_protobuf/ (allocs/op) 870,147 allocs 870,053 allocs 🟢 -0.01%
BenchmarkVersionVector
Benchmark suite Previous Current Change
clients_10/ (ns/op) 160.21 ms 171.98 ms 🔴 +7.34%
clients_10/ (1_changepack(bytes)) 745.00 B 745.00 B ⚪ 0%
clients_10/ (2_snapshot(bytes)) 379.00 B 379.00 B ⚪ 0%
clients_10/ (3_pushpull(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (4_attach(ms)) 6.00 ms 6.00 ms ⚪ 0%
clients_10/ (5_changepack_after_detach(bytes)) 805.00 B 805.00 B ⚪ 0%
clients_10/ (6_snapshot_after_detach(bytes)) 136.00 B 136.00 B ⚪ 0%
clients_10/ (7_pushpull_after_detach(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (B/op) 19.93 MB 20.94 MB 🔴 +5.05%
clients_10/ (allocs/op) 83,762 allocs 83,378 allocs 🟢 -0.46%
clients_100/ (ns/op) 1.41 s 1.50 s 🔴 +6.33%
clients_100/ (1_changepack(bytes)) 6.14 KB 6.14 KB ⚪ 0%
clients_100/ (2_snapshot(bytes)) 3.08 KB 3.08 KB ⚪ 0%
clients_100/ (3_pushpull(ms)) 11.00 ms 12.00 ms 🔴 +9.09%
clients_100/ (4_attach(ms)) 11.00 ms 10.00 ms 🟢 -9.09%
clients_100/ (5_changepack_after_detach(bytes)) 6.21 KB 6.21 KB ⚪ 0%
clients_100/ (6_snapshot_after_detach(bytes)) 137.00 B 137.00 B ⚪ 0%
clients_100/ (7_pushpull_after_detach(ms)) 9.00 ms 10.00 ms 🔴 +11.11%
clients_100/ (B/op) 230.31 MB 217.05 MB 🟢 -5.76%
clients_100/ (allocs/op) 1,539,768 allocs 1,484,440 allocs 🟢 -3.59%
clients_1000/ (ns/op) 60.97 s 48.76 s 🟢 -20.03%
clients_1000/ (1_changepack(bytes)) 60.16 KB 60.16 KB ⚪ 0%
clients_1000/ (2_snapshot(bytes)) 30.08 KB 30.08 KB ⚪ 0%
clients_1000/ (3_pushpull(ms)) 95.00 ms 96.00 ms 🔴 +1.05%
clients_1000/ (4_attach(ms)) 249.00 ms 104.00 ms 🟢 -58.23%
clients_1000/ (5_changepack_after_detach(bytes)) 60.22 KB 60.22 KB ⚪ 0%
clients_1000/ (6_snapshot_after_detach(bytes)) 139.00 B 139.00 B ⚪ 0%
clients_1000/ (7_pushpull_after_detach(ms)) 26.00 ms 24.00 ms 🟢 -7.69%
clients_1000/ (B/op) 22.07 GB 6.58 GB 🟢 -70.16%
clients_1000/ (allocs/op) 111,762,106 allocs 93,477,305 allocs 🟢 -16.36%

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 31.42857% with 24 lines in your changes missing coverage. Please review.

Project coverage is 38.32%. Comparing base (44e7632) to head (90a0c9c).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pkg/document/time/version_vector.go 36.36% 13 Missing and 1 partial ⚠️
pkg/document/change/id.go 0.00% 4 Missing ⚠️
pkg/document/internal_document.go 20.00% 4 Missing ⚠️
server/backend/database/memory/database.go 0.00% 1 Missing ⚠️
server/backend/database/mongo/client.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1164      +/-   ##
==========================================
- Coverage   38.56%   38.32%   -0.24%     
==========================================
  Files         170      172       +2     
  Lines       25441    25803     +362     
==========================================
+ Hits         9812     9890      +78     
- Misses      14808    15079     +271     
- Partials      821      834      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hackerwins-yorkie hackerwins-yorkie marked this pull request as ready for review February 20, 2025 08:38
Copy link

@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: 0

🧹 Nitpick comments (1)
api/converter/from_pb.go (1)

154-184: Memory optimization achieved through improved error handling.

The changes successfully optimize memory efficiency by:

  1. Avoiding unnecessary version vector copies during error handling
  2. Using initial values instead of default copies
  3. Maintaining consistent error handling patterns

This aligns well with the PR's objective of improving memory efficiency.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1f1ae and a596d99.

📒 Files selected for processing (5)
  • api/converter/from_pb.go (1 hunks)
  • pkg/document/change/id.go (2 hunks)
  • pkg/document/internal_document.go (2 hunks)
  • pkg/document/time/version_vector.go (1 hunks)
  • test/helper/helper.go (1 hunks)
🔇 Additional comments (9)
pkg/document/time/version_vector.go (1)

159-183: LGTM! The optimization improves memory efficiency.

The changes effectively optimize memory usage by:

  1. Modifying the vector in place instead of creating a new one.
  2. Using pointer parameter to avoid unnecessary copies.

Note: The implementation correctly handles the nil case and properly dereferences the pointer when accessing elements.

pkg/document/change/id.go (2)

116-116: LGTM! Correctly adapted to the new Max method signature.

The call to Max has been updated to pass a pointer to otherVV, aligning with the optimized implementation.


138-138: LGTM! Correctly adapted to the new Max method signature.

The call to Max has been updated to pass a pointer to vector, aligning with the optimized implementation.

pkg/document/internal_document.go (2)

100-105: LGTM! Improved initialization with explicit parameters.

The initialization now uses change.NewID with explicit parameters, making the code more maintainable and easier to understand.


124-130: LGTM! Consistent initialization pattern.

The initialization follows the same pattern as in NewInternalDocument, maintaining consistency across the codebase.

test/helper/helper.go (1)

120-125: LGTM! Consistent with the new initialization pattern.

The test helper has been updated to use change.NewID with explicit parameters, maintaining consistency with the changes in the main codebase.

api/converter/from_pb.go (3)

157-164: LGTM: Consistent error handling with initial values.

The error handling for actorID conversion now returns a new change ID with initial values, which is more informative than returning a default ID.


168-175: LGTM: Consistent error handling pattern.

The error handling for version vector conversion follows the same pattern, maintaining consistency in the codebase.


177-183: LGTM: Proper initialization of change ID.

The successful case properly initializes a new change ID with all required parameters.

Copy link

@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: 0

🧹 Nitpick comments (1)
pkg/document/internal_document.go (1)

100-100: Improve readability by breaking down the long line.

The line exceeds the maximum length of 120 characters. Consider reformatting for better readability.

-		changeID:      change.NewID(change.InitialClientSeq, change.InitialServerSeq, change.InitialLamport, time.InitialActorID, time.NewVersionVector()),
+		changeID: change.NewID(
+			change.InitialClientSeq,
+			change.InitialServerSeq,
+			change.InitialLamport,
+			time.InitialActorID,
+			time.NewVersionVector(),
+		),
🧰 Tools
🪛 golangci-lint (1.62.2)

100-100: the line is 149 characters long, which exceeds the maximum of 120 characters.

(lll)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a596d99 and f219d23.

📒 Files selected for processing (3)
  • api/converter/from_pb.go (1 hunks)
  • pkg/document/internal_document.go (2 hunks)
  • test/helper/helper.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/converter/from_pb.go
  • test/helper/helper.go
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/document/internal_document.go

100-100: the line is 149 characters long, which exceeds the maximum of 120 characters.

(lll)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: complex-test
  • GitHub Check: bench
  • GitHub Check: build
🔇 Additional comments (2)
pkg/document/internal_document.go (2)

119-126: LGTM! Well-structured initialization.

The code is well-organized with each parameter on a new line, making it easy to read and maintain. The use of SetClocks after initialization properly sets the lamport and vector values.


134-134: LGTM! Simple and clear assignment.

The assignment of the constructed changeID is straightforward and clear.

Copy link

@hackerwins-yorkie hackerwins-yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark Analysis 📊

This is a comparison result between the previous(e687d61) and the current commit(b42eab4).

Significant Changes (≥20% difference)

Benchmark suite Previous Current Change
BenchmarkVersionVector/clients_1000/ (B/op) 22.07 GB 6.59 GB 🟢 -70.14%
BenchmarkVersionVector/clients_1000/ (4_attach(ms)) 249.00 ms 102.00 ms 🟢 -59.04%
BenchmarkVersionVector/clients_100/ (3_pushpull(ms)) 11.00 ms 15.00 ms 🔴 +36.36%
BenchmarkVersionVector/clients_1000/ (ns/op) 60.97 s 47.44 s 🟢 -22.20%

Key Observations 🔍

  1. BenchmarkVersionVector:

    • For the suite BenchmarkVersionVector/clients_1000/, significant improvements were seen:
      • There was a remarkable decrease in memory usage by approximately 70.14%.
      • The 4_attach operation time reduced significantly by about 59.04%.
    • Notably, the 3_pushpull operation time for clients_100/ increased by approximately 36.36%.
  2. BenchmarkSnapshot:

    • In the suite BenchmarkSnapshot, the data showed fluctuations in performance:
      • The operation time for Pull_30KB_snapshot slightly increased by 0.33%.
      • However, for Push_30KB_snapshot, the operation time increased by 5.22%.
  3. BenchmarkRPC:

    • Suite BenchmarkRPC highlighted improvements as well as minor setbacks:
      • client_to_server operation time increased slightly by 0.07%.
      • Notably, memory usage decreased for client_to_server and adminCli_to_server operations by 0.12% and 6.07% respectively.
  4. Overall Trends:

    • Across various benchmark suites, there were instances of both improvements and declines in performance metrics.
    • Generally, there seemed to be more instances of performance enhancements (🟢) than deteriorations (🔴).
    • Memory optimizations were observed in several benchmarks, suggesting efficiency gains in resource management.
    • Operation times fluctuated, with some operations showing considerable variations in performance.

Overall, the benchmark data reflects a mix of improvements and declines in different performance aspects, showcasing the dynamic nature of optimizations and regressions in the tested scenarios.

Clock Analysis

Lamport (v0.5.2)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 84.96 ms 793.94 ms 34.79 s
Memory Allocations 35.11 MB 219.92 MB 4.91 GB
Number of Allocations (allocs/op) 69,271 1,246,728 81,485,288
ChangePack Size 138.0 B 137.0 B 141.0 B
Snapshot Size 379.0 B 3.08 KB 30.08 KB
Push-Pull Time 2.0 ms 1.5 ms 4.0 ms
Attach Time 4.5 ms 11.0 ms 31.0 ms
ChangePack After Detach 138.0 B 140.0 B 141.0 B
Snapshot After Detach 136.0 B 137.0 B 139.0 B
Push-Pull After Detach 2.5 ms 5.0 ms 9.5 ms

VV (current)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 163.10 ms 1.46 s 47.44 s
Memory Allocations 20.28 MB 215.40 MB 6.59 GB
Number of Allocations (allocs/op) 83,354 1,484,696 93,478,838
ChangePack Size 745.00 B 6.14 KB 60.16 KB
Snapshot Size 379.00 B 3.08 KB 30.08 KB
Push-Pull Time 8.00 ms 15.00 ms 95.00 ms
Attach Time 6.00 ms 10.00 ms 102.00 ms
ChangePack After Detach 805.00 B 6.21 KB 60.22 KB
Snapshot After Detach 136.00 B 137.00 B 139.00 B
Push-Pull After Detach 8.00 ms 9.00 ms 23.00 ms

Summary

  • Lamport clock generally performs better in terms of total operation time across all client loads compared to the Version Vector.
  • Version Vector has higher memory allocations and number of allocations as the number of clients increases, indicating a more resource-intensive operation.
  • Push-Pull time for Version Vector drastically increases with 1000 clients, suggesting potential scalability challenges.
  • Attach times for Lamport are generally lower than Version Vector, indicating faster processing of operations.
  • ChangePack and Snapshot sizes are smaller for Lamport across all client loads, showing better efficiency in data representation.
  • The Version Vector shows significant improvements in total operation time and memory usage with 1000 clients compared to Lamport clock.

Detailed Test Results

BenchmarkDocument
Benchmark suite Previous Current Change
constructor_test/ (ns/op) 1439.00 ns 1475.00 ns 🔴 +2.50%
constructor_test/ (B/op) 1.39 KB 1.43 KB 🔴 +3.47%
constructor_test/ (allocs/op) 24 allocs 25 allocs 🔴 +4.17%
status_test/ (ns/op) 1028.00 ns 1078.00 ns 🔴 +4.86%
status_test/ (B/op) 1.35 KB 1.40 KB 🔴 +3.55%
status_test/ (allocs/op) 22 allocs 23 allocs 🔴 +4.55%
equals_test/ (ns/op) 7864.00 ns 8013.00 ns 🔴 +1.89%
equals_test/ (B/op) 7.56 KB 7.71 KB 🔴 +1.90%
equals_test/ (allocs/op) 129 allocs 132 allocs 🔴 +2.33%
nested_update_test/ (ns/op) 17079.00 ns 17841.00 ns 🔴 +4.46%
nested_update_test/ (B/op) 12.31 KB 12.36 KB 🔴 +0.39%
nested_update_test/ (allocs/op) 258 allocs 259 allocs 🔴 +0.39%
delete_test/ (ns/op) 27313.00 ns 26273.00 ns 🟢 -3.81%
delete_test/ (B/op) 15.79 KB 15.84 KB 🔴 +0.30%
delete_test/ (allocs/op) 339 allocs 340 allocs 🔴 +0.29%
object_test/ (ns/op) 8546.00 ns 8628.00 ns 🔴 +0.96%
object_test/ (B/op) 7.03 KB 7.08 KB 🔴 +0.70%
object_test/ (allocs/op) 118 allocs 119 allocs 🔴 +0.85%
array_test/ (ns/op) 28984.00 ns 28377.00 ns 🟢 -2.09%
array_test/ (B/op) 12.14 KB 12.19 KB 🔴 +0.40%
array_test/ (allocs/op) 273 allocs 274 allocs 🔴 +0.37%
text_test/ (ns/op) 32155.00 ns 32560.00 ns 🔴 +1.26%
text_test/ (B/op) 15.19 KB 15.24 KB 🔴 +0.32%
text_test/ (allocs/op) 484 allocs 485 allocs 🔴 +0.21%
text_composition_test/ (ns/op) 31674.00 ns 32523.00 ns 🔴 +2.68%
text_composition_test/ (B/op) 18.70 KB 18.75 KB 🔴 +0.26%
text_composition_test/ (allocs/op) 501 allocs 502 allocs 🔴 +0.20%
rich_text_test/ (ns/op) 87424.00 ns 85796.00 ns 🟢 -1.86%
rich_text_test/ (B/op) 39.36 KB 39.40 KB 🔴 +0.12%
rich_text_test/ (allocs/op) 1,146 allocs 1,147 allocs 🔴 +0.09%
counter_test/ (ns/op) 18201.00 ns 18619.00 ns 🔴 +2.30%
counter_test/ (B/op) 11.81 KB 11.86 KB 🔴 +0.41%
counter_test/ (allocs/op) 253 allocs 254 allocs 🔴 +0.40%
text_edit_gc_100/ (ns/op) 1.39 ms 1.40 ms 🔴 +0.62%
text_edit_gc_100/ (B/op) 864.90 KB 864.91 KB ⚪ 0%
text_edit_gc_100/ (allocs/op) 17,281 allocs 17,282 allocs ⚪ 0%
text_edit_gc_1000/ (ns/op) 53.39 ms 53.93 ms 🔴 +1.01%
text_edit_gc_1000/ (B/op) 46.84 MB 46.84 MB ⚪ 0%
text_edit_gc_1000/ (allocs/op) 185,598 allocs 185,590 allocs ⚪ 0%
text_split_gc_100/ (ns/op) 2.12 ms 2.13 ms 🔴 +0.21%
text_split_gc_100/ (B/op) 1.58 MB 1.58 MB ⚪ 0%
text_split_gc_100/ (allocs/op) 15,950 allocs 15,952 allocs 🔴 +0.01%
text_split_gc_1000/ (ns/op) 128.25 ms 131.55 ms 🔴 +2.58%
text_split_gc_1000/ (B/op) 137.79 MB 137.79 MB ⚪ 0%
text_split_gc_1000/ (allocs/op) 185,000 allocs 184,991 allocs ⚪ 0%
text_delete_all_10000/ (ns/op) 18.43 ms 17.48 ms 🟢 -5.16%
text_delete_all_10000/ (B/op) 10.58 MB 10.58 MB ⚪ 0%
text_delete_all_10000/ (allocs/op) 56,134 allocs 56,135 allocs ⚪ 0%
text_delete_all_100000/ (ns/op) 312.31 ms 271.82 ms 🟢 -12.96%
text_delete_all_100000/ (B/op) 105.54 MB 105.52 MB 🟢 -0.02%
text_delete_all_100000/ (allocs/op) 566,133 allocs 566,112 allocs ⚪ 0%
text_100/ (ns/op) 234634.00 ns 238225.00 ns 🔴 +1.53%
text_100/ (B/op) 120.94 KB 120.96 KB 🔴 +0.01%
text_100/ (allocs/op) 5,181 allocs 5,182 allocs 🔴 +0.02%
text_1000/ (ns/op) 2.46 ms 2.52 ms 🔴 +2.06%
text_1000/ (B/op) 1.16 MB 1.16 MB ⚪ 0%
text_1000/ (allocs/op) 51,084 allocs 51,085 allocs ⚪ 0%
array_1000/ (ns/op) 1.24 ms 1.29 ms 🔴 +3.72%
array_1000/ (B/op) 1.09 MB 1.09 MB ⚪ 0%
array_1000/ (allocs/op) 11,879 allocs 11,880 allocs ⚪ 0%
array_10000/ (ns/op) 13.33 ms 13.83 ms 🔴 +3.68%
array_10000/ (B/op) 9.89 MB 9.89 MB ⚪ 0%
array_10000/ (allocs/op) 120,735 allocs 120,738 allocs ⚪ 0%
array_gc_100/ (ns/op) 131750.00 ns 138209.00 ns 🔴 +4.90%
array_gc_100/ (B/op) 99.89 KB 99.94 KB 🔴 +0.05%
array_gc_100/ (allocs/op) 1,266 allocs 1,267 allocs 🔴 +0.08%
array_gc_1000/ (ns/op) 1.42 ms 1.48 ms 🔴 +3.99%
array_gc_1000/ (B/op) 1.14 MB 1.14 MB ⚪ 0%
array_gc_1000/ (allocs/op) 12,926 allocs 12,927 allocs ⚪ 0%
counter_1000/ (ns/op) 202098.00 ns 207995.00 ns 🔴 +2.92%
counter_1000/ (B/op) 178.13 KB 178.19 KB 🔴 +0.03%
counter_1000/ (allocs/op) 5,771 allocs 5,772 allocs 🔴 +0.02%
counter_10000/ (ns/op) 2.17 ms 2.17 ms 🔴 +0.22%
counter_10000/ (B/op) 2.07 MB 2.07 MB ⚪ 0%
counter_10000/ (allocs/op) 59,778 allocs 59,779 allocs ⚪ 0%
object_1000/ (ns/op) 1.39 ms 1.47 ms 🔴 +6.02%
object_1000/ (B/op) 1.44 MB 1.44 MB 🔴 +0.02%
object_1000/ (allocs/op) 9,925 allocs 9,926 allocs 🔴 +0.01%
object_10000/ (ns/op) 14.82 ms 15.26 ms 🔴 +2.98%
object_10000/ (B/op) 12.35 MB 12.35 MB 🟢 -0.01%
object_10000/ (allocs/op) 101,232 allocs 101,227 allocs ⚪ 0%
tree_100/ (ns/op) 1.02 ms 1.08 ms 🔴 +5.24%
tree_100/ (B/op) 951.02 KB 951.08 KB ⚪ 0%
tree_100/ (allocs/op) 6,102 allocs 6,103 allocs 🔴 +0.02%
tree_1000/ (ns/op) 74.23 ms 80.32 ms 🔴 +8.20%
tree_1000/ (B/op) 86.58 MB 86.58 MB ⚪ 0%
tree_1000/ (allocs/op) 60,111 allocs 60,112 allocs ⚪ 0%
tree_10000/ (ns/op) 9.68 s 9.83 s 🔴 +1.58%
tree_10000/ (B/op) 8.58 GB 8.58 GB ⚪ 0%
tree_10000/ (allocs/op) 600,173 allocs 600,184 allocs ⚪ 0%
tree_delete_all_1000/ (ns/op) 78.41 ms 79.86 ms 🔴 +1.85%
tree_delete_all_1000/ (B/op) 87.57 MB 87.57 MB ⚪ 0%
tree_delete_all_1000/ (allocs/op) 75,289 allocs 75,290 allocs ⚪ 0%
tree_edit_gc_100/ (ns/op) 3.96 ms 3.95 ms 🟢 -0.37%
tree_edit_gc_100/ (B/op) 4.15 MB 4.15 MB ⚪ 0%
tree_edit_gc_100/ (allocs/op) 15,147 allocs 15,147 allocs ⚪ 0%
tree_edit_gc_1000/ (ns/op) 332.75 ms 327.34 ms 🟢 -1.62%
tree_edit_gc_1000/ (B/op) 384.04 MB 384.05 MB ⚪ 0%
tree_edit_gc_1000/ (allocs/op) 154,952 allocs 154,955 allocs ⚪ 0%
tree_split_gc_100/ (ns/op) 2.67 ms 2.70 ms 🔴 +1.21%
tree_split_gc_100/ (B/op) 2.41 MB 2.41 MB ⚪ 0%
tree_split_gc_100/ (allocs/op) 11,131 allocs 11,132 allocs ⚪ 0%
tree_split_gc_1000/ (ns/op) 197.74 ms 202.90 ms 🔴 +2.61%
tree_split_gc_1000/ (B/op) 222.50 MB 222.50 MB ⚪ 0%
tree_split_gc_1000/ (allocs/op) 122,053 allocs 122,076 allocs 🔴 +0.02%
BenchmarkRPC
Benchmark suite Previous Current Change
client_to_server/ (ns/op) 431.85 ms 432.17 ms 🔴 +0.07%
client_to_server/ (B/op) 16.13 MB 16.11 MB 🟢 -0.12%
client_to_server/ (allocs/op) 223,674 allocs 223,174 allocs 🟢 -0.22%
client_to_client_via_server/ (ns/op) 788.62 ms 813.18 ms 🔴 +3.11%
client_to_client_via_server/ (B/op) 37.20 MB 37.05 MB 🟢 -0.42%
client_to_client_via_server/ (allocs/op) 478,656 allocs 481,677 allocs 🔴 +0.63%
attach_large_document/ (ns/op) 1.32 s 1.32 s 🟢 -0.26%
attach_large_document/ (B/op) 1.89 GB 1.90 GB 🔴 +0.62%
attach_large_document/ (allocs/op) 12,321 allocs 12,507 allocs 🔴 +1.51%
adminCli_to_server/ (ns/op) 542.08 ms 550.59 ms 🔴 +1.57%
adminCli_to_server/ (B/op) 21.76 MB 20.44 MB 🟢 -6.07%
adminCli_to_server/ (allocs/op) 291,952 allocs 291,920 allocs 🟢 -0.01%
BenchmarkLocker
Benchmark suite Previous Current Change
(ns/op) 82.86 ns 81.11 ns 🟢 -2.11%
(B/op) 32.00 B 32.00 B ⚪ 0%
(allocs/op) 1 allocs 1 allocs ⚪ 0%
BenchmarkLockerParallel
Benchmark suite Previous Current Change
(ns/op) 45.80 ns 45.46 ns 🟢 -0.74%
(B/op) 0.00 B 0.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkLockerMoreKeys
Benchmark suite Previous Current Change
(ns/op) 180.50 ns 181.60 ns 🔴 +0.61%
(B/op) 31.00 B 30.00 B 🟢 -3.23%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkRWLocker
Benchmark suite Previous Current Change
RWLock_rate_2/ (ns/op) 50.25 ns 49.86 ns 🟢 -0.78%
RWLock_rate_2/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_2/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_10/ (ns/op) 44.88 ns 44.20 ns 🟢 -1.52%
RWLock_rate_10/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_10/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_100/ (ns/op) 63.08 ns 62.20 ns 🟢 -1.40%
RWLock_rate_100/ (B/op) 2.00 B 2.00 B ⚪ 0%
RWLock_rate_100/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_1000/ (ns/op) 91.91 ns 100.90 ns 🔴 +9.78%
RWLock_rate_1000/ (B/op) 8.00 B 8.00 B ⚪ 0%
RWLock_rate_1000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkChange
Benchmark suite Previous Current Change
Push_10_Changes/ (ns/op) 4.54 ms 4.62 ms 🔴 +1.73%
Push_10_Changes/ (B/op) 150.42 KB 149.92 KB 🟢 -0.33%
Push_10_Changes/ (allocs/op) 1,623 allocs 1,623 allocs ⚪ 0%
Push_100_Changes/ (ns/op) 16.52 ms 16.98 ms 🔴 +2.83%
Push_100_Changes/ (B/op) 770.59 KB 778.21 KB 🔴 +0.99%
Push_100_Changes/ (allocs/op) 8,509 allocs 8,510 allocs 🔴 +0.01%
Push_1000_Changes/ (ns/op) 129.20 ms 135.59 ms 🔴 +4.95%
Push_1000_Changes/ (B/op) 7.22 MB 7.24 MB 🔴 +0.30%
Push_1000_Changes/ (allocs/op) 79,325 allocs 79,325 allocs ⚪ 0%
Pull_10_Changes/ (ns/op) 3.70 ms 3.79 ms 🔴 +2.26%
Pull_10_Changes/ (B/op) 124.59 KB 124.42 KB 🟢 -0.14%
Pull_10_Changes/ (allocs/op) 1,456 allocs 1,457 allocs 🔴 +0.07%
Pull_100_Changes/ (ns/op) 5.32 ms 5.48 ms 🔴 +2.93%
Pull_100_Changes/ (B/op) 354.61 KB 353.56 KB 🟢 -0.29%
Pull_100_Changes/ (allocs/op) 5,182 allocs 5,181 allocs 🟢 -0.02%
Pull_1000_Changes/ (ns/op) 10.88 ms 11.10 ms 🔴 +2.11%
Pull_1000_Changes/ (B/op) 2.20 MB 2.20 MB 🟢 -0.20%
Pull_1000_Changes/ (allocs/op) 44,681 allocs 44,681 allocs ⚪ 0%
BenchmarkSnapshot
Benchmark suite Previous Current Change
Push_3KB_snapshot/ (ns/op) 19.55 ms 19.35 ms 🟢 -1.04%
Push_3KB_snapshot/ (B/op) 905.58 KB 897.33 KB 🟢 -0.91%
Push_3KB_snapshot/ (allocs/op) 8,516 allocs 8,511 allocs 🟢 -0.06%
Push_30KB_snapshot/ (ns/op) 132.18 ms 139.08 ms 🔴 +5.22%
Push_30KB_snapshot/ (B/op) 8.24 MB 8.07 MB 🟢 -2.14%
Push_30KB_snapshot/ (allocs/op) 89,008 allocs 88,660 allocs 🟢 -0.39%
Pull_3KB_snapshot/ (ns/op) 7.80 ms 7.53 ms 🟢 -3.53%
Pull_3KB_snapshot/ (B/op) 1.12 MB 1.06 MB 🟢 -5.10%
Pull_3KB_snapshot/ (allocs/op) 20,064 allocs 19,256 allocs 🟢 -4.03%
Pull_30KB_snapshot/ (ns/op) 19.91 ms 19.98 ms 🔴 +0.33%
Pull_30KB_snapshot/ (B/op) 9.31 MB 8.76 MB 🟢 -5.90%
Pull_30KB_snapshot/ (allocs/op) 193,610 allocs 185,677 allocs 🟢 -4.10%
BenchmarkSplayTree
Benchmark suite Previous Current Change
stress_test_100000/ (ns/op) 0.19 ns 0.19 ns 🟢 -2.79%
stress_test_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_200000/ (ns/op) 0.40 ns 0.41 ns 🔴 +2.76%
stress_test_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_300000/ (ns/op) 0.57 ns 0.59 ns 🔴 +3.10%
stress_test_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_100000/ (ns/op) 0.01 ns 0.01 ns 🔴 +4.01%
random_access_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_200000/ (ns/op) 0.03 ns 0.03 ns 🟢 -0.88%
random_access_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_300000/ (ns/op) 0.04 ns 0.05 ns 🔴 +4.39%
random_access_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
editing_trace_bench/ (ns/op) 0.00 ns 0.00 ns 🔴 +10.65%
editing_trace_bench/ (B/op) 0.00 B 0.00 B ⚪ 0%
editing_trace_bench/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkSync
Benchmark suite Previous Current Change
memory_sync_10_test/ (ns/op) 7288.00 ns 7104.00 ns 🟢 -2.52%
memory_sync_10_test/ (B/op) 1.34 KB 1.34 KB ⚪ 0%
memory_sync_10_test/ (allocs/op) 35 allocs 35 allocs ⚪ 0%
memory_sync_100_test/ (ns/op) 55353.00 ns 56751.00 ns 🔴 +2.53%
memory_sync_100_test/ (B/op) 9.51 KB 9.50 KB 🟢 -0.02%
memory_sync_100_test/ (allocs/op) 268 allocs 268 allocs ⚪ 0%
memory_sync_1000_test/ (ns/op) 616285.00 ns 635101.00 ns 🔴 +3.05%
memory_sync_1000_test/ (B/op) 75.92 KB 75.60 KB 🟢 -0.42%
memory_sync_1000_test/ (allocs/op) 2,111 allocs 2,101 allocs 🟢 -0.47%
memory_sync_10000_test/ (ns/op) 7.47 ms 8.11 ms 🔴 +8.56%
memory_sync_10000_test/ (B/op) 761.49 KB 755.20 KB 🟢 -0.83%
memory_sync_10000_test/ (allocs/op) 20,475 allocs 20,463 allocs 🟢 -0.06%
BenchmarkTextEditing
Benchmark suite Previous Current Change
(ns/op) 5.18 s 5.44 s 🔴 +5.11%
(B/op) 3.92 GB 3.92 GB ⚪ 0%
(allocs/op) 20,619,777 allocs 20,619,840 allocs ⚪ 0%
BenchmarkTree
Benchmark suite Previous Current Change
10000_vertices_to_protobuf/ (ns/op) 4.17 ms 4.33 ms 🔴 +3.85%
10000_vertices_to_protobuf/ (B/op) 6.36 MB 6.36 MB ⚪ 0%
10000_vertices_to_protobuf/ (allocs/op) 70,025 allocs 70,025 allocs ⚪ 0%
10000_vertices_from_protobuf/ (ns/op) 217.30 ms 234.82 ms 🔴 +8.06%
10000_vertices_from_protobuf/ (B/op) 442.30 MB 442.31 MB ⚪ 0%
10000_vertices_from_protobuf/ (allocs/op) 290,038 allocs 290,057 allocs ⚪ 0%
20000_vertices_to_protobuf/ (ns/op) 8.84 ms 9.27 ms 🔴 +4.92%
20000_vertices_to_protobuf/ (B/op) 12.89 MB 12.89 MB ⚪ 0%
20000_vertices_to_protobuf/ (allocs/op) 140,028 allocs 140,028 allocs ⚪ 0%
20000_vertices_from_protobuf/ (ns/op) 884.61 ms 902.85 ms 🔴 +2.06%
20000_vertices_from_protobuf/ (B/op) 1.70 GB 1.70 GB ⚪ 0%
20000_vertices_from_protobuf/ (allocs/op) 580,043 allocs 580,046 allocs ⚪ 0%
30000_vertices_to_protobuf/ (ns/op) 14.26 ms 14.73 ms 🔴 +3.29%
30000_vertices_to_protobuf/ (B/op) 18.98 MB 18.98 MB ⚪ 0%
30000_vertices_to_protobuf/ (allocs/op) 210,029 allocs 210,030 allocs ⚪ 0%
30000_vertices_from_protobuf/ (ns/op) 2.00 s 2.03 s 🔴 +1.20%
30000_vertices_from_protobuf/ (B/op) 3.75 GB 3.75 GB ⚪ 0%
30000_vertices_from_protobuf/ (allocs/op) 870,147 allocs 870,056 allocs 🟢 -0.01%
BenchmarkVersionVector
Benchmark suite Previous Current Change
clients_10/ (ns/op) 160.21 ms 163.10 ms 🔴 +1.80%
clients_10/ (1_changepack(bytes)) 745.00 B 745.00 B ⚪ 0%
clients_10/ (2_snapshot(bytes)) 379.00 B 379.00 B ⚪ 0%
clients_10/ (3_pushpull(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (4_attach(ms)) 6.00 ms 6.00 ms ⚪ 0%
clients_10/ (5_changepack_after_detach(bytes)) 805.00 B 805.00 B ⚪ 0%
clients_10/ (6_snapshot_after_detach(bytes)) 136.00 B 136.00 B ⚪ 0%
clients_10/ (7_pushpull_after_detach(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (B/op) 19.93 MB 20.28 MB 🔴 +1.73%
clients_10/ (allocs/op) 83,762 allocs 83,354 allocs 🟢 -0.49%
clients_100/ (ns/op) 1.41 s 1.46 s 🔴 +3.55%
clients_100/ (1_changepack(bytes)) 6.14 KB 6.14 KB ⚪ 0%
clients_100/ (2_snapshot(bytes)) 3.08 KB 3.08 KB ⚪ 0%
clients_100/ (3_pushpull(ms)) 11.00 ms 15.00 ms 🔴 +36.36%
clients_100/ (4_attach(ms)) 11.00 ms 10.00 ms 🟢 -9.09%
clients_100/ (5_changepack_after_detach(bytes)) 6.21 KB 6.21 KB ⚪ 0%
clients_100/ (6_snapshot_after_detach(bytes)) 137.00 B 137.00 B ⚪ 0%
clients_100/ (7_pushpull_after_detach(ms)) 9.00 ms 9.00 ms ⚪ 0%
clients_100/ (B/op) 230.31 MB 215.40 MB 🟢 -6.47%
clients_100/ (allocs/op) 1,539,768 allocs 1,484,696 allocs 🟢 -3.58%
clients_1000/ (ns/op) 60.97 s 47.44 s 🟢 -22.20%
clients_1000/ (1_changepack(bytes)) 60.16 KB 60.16 KB ⚪ 0%
clients_1000/ (2_snapshot(bytes)) 30.08 KB 30.08 KB ⚪ 0%
clients_1000/ (3_pushpull(ms)) 95.00 ms 95.00 ms ⚪ 0%
clients_1000/ (4_attach(ms)) 249.00 ms 102.00 ms 🟢 -59.04%
clients_1000/ (5_changepack_after_detach(bytes)) 60.22 KB 60.22 KB ⚪ 0%
clients_1000/ (6_snapshot_after_detach(bytes)) 139.00 B 139.00 B ⚪ 0%
clients_1000/ (7_pushpull_after_detach(ms)) 26.00 ms 23.00 ms 🟢 -11.54%
clients_1000/ (B/op) 22.07 GB 6.59 GB 🟢 -70.14%
clients_1000/ (allocs/op) 111,762,106 allocs 93,478,838 allocs 🟢 -16.36%

Copy link

@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: 0

🧹 Nitpick comments (1)
pkg/document/internal_document.go (1)

124-130: Simplify changeID initialization.

The current two-step initialization can be simplified by directly passing the actual values to change.NewID.

-	changeID := change.NewID(
-		change.InitialClientSeq,
-		change.InitialServerSeq,
-		change.InitialLamport,
-		time.InitialActorID,
-		time.NewVersionVector())
-	changeID.SetClocks(lamport, vector)
+	changeID := change.NewID(
+		change.InitialClientSeq,
+		change.InitialServerSeq,
+		lamport,
+		time.InitialActorID,
+		vector)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f219d23 and 75ddf38.

📒 Files selected for processing (3)
  • api/converter/from_pb.go (1 hunks)
  • pkg/document/internal_document.go (2 hunks)
  • test/helper/helper.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/converter/from_pb.go
  • test/helper/helper.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: bench
  • GitHub Check: complex-test
  • GitHub Check: build
🔇 Additional comments (2)
pkg/document/internal_document.go (2)

100-105: LGTM! Improved initialization of changeID.

The explicit initialization of changeID using change.NewID with initial values improves code clarity and maintainability.


297-346:

❓ Verification inconclusive

Verify alignment with PR objectives.

The PR objectives mention optimizing max VersionVector in ApplyChanges for memory efficiency, but the changes in this file focus on changeID initialization instead. The ApplyChanges method remains unchanged. Please clarify if additional changes are needed to achieve the memory optimization goal.


🏁 Script executed:

#!/bin/bash
# Description: Search for other files that might contain the optimization changes
# mentioned in the PR objectives.

echo "Searching for files containing VersionVector and ApplyChanges..."
rg -l "VersionVector.*ApplyChanges|ApplyChanges.*VersionVector"

echo "Searching for Max method implementation in version vector..."
ast-grep --pattern 'func $_($$) Max($_, $_) {
  $$$
}'

Length of output: 392


Clarify Memory Optimization Alignment

  • The PR objectives target optimizing the max VersionVector for memory efficiency in ApplyChanges, yet the changes in this file focus solely on changeID initialization.
  • Our search did not reveal any modifications regarding VersionVector or its Max method in this or adjacent files.
  • Please confirm if additional updates addressing the VersionVector optimization are intended, or if these changes appear in another segment of the PR.

Copy link

@hackerwins-yorkie hackerwins-yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark Analysis 📊

This is a comparison result between the previous(e687d61) and the current commit(d1c0be0).

Significant Changes (≥20% difference)

Benchmark suite Previous Current Change
BenchmarkVersionVector/clients_1000/ (B/op) 22.07 GB 6.59 GB 🟢 -70.15%
BenchmarkVersionVector/clients_1000/ (4_attach(ms)) 249.00 ms 101.00 ms 🟢 -59.44%
BenchmarkVersionVector/clients_1000/ (ns/op) 60.97 s 47.55 s 🟢 -22.02%

Key Observations 🔍

  • The BenchmarkVersionVector/clients_1000/ suite exhibited significant improvements across multiple metrics:

    • A remarkable 70.15% decrease in memory usage (B/op) from 22.07 GB to 6.59 GB.
    • The time taken for attachment (4_attach(ms)) was reduced by 59.44% from 249.00 ms to 101.00 ms.
    • The execution time (ns/op) saw a notable 22.02% decrease from 60.97 s to 47.55 s.
  • The BenchmarkRPC suite showed noteworthy reduction across several benchmarks:

    • client_to_client_via_server/ (B/op) witnessed an 8.06% decrease in memory usage.
    • attach_large_document/ (ns/op) experienced a significant 5.91% decrease in execution time.
    • adminCli_to_server/ (B/op) demonstrated a 6.35% decrease in memory usage.
  • Overall, in the various benchmark suites, a trend of optimization and efficiency improvement is observed, with a predominant focus on reducing memory consumption and execution times.

Clock Analysis

Lamport (v0.5.2)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 84.96 ms 793.94 ms 34.79 s
Memory Allocations 35.11 MB 219.92 MB 4.91 GB
Number of Allocations (allocs/op) 69,271 1,246,728 81,485,288
ChangePack Size 138.0 B 137.0 B 141.0 B
Snapshot Size 379.0 B 3.08 KB 30.08 KB
Push-Pull Time 2.0 ms 1.5 ms 4.0 ms
Attach Time 4.5 ms 11.0 ms 31.0 ms
ChangePack After Detach 138.0 B 140.0 B 141.0 B
Snapshot After Detach 136.0 B 137.0 B 139.0 B
Push-Pull After Detach 2.5 ms 5.0 ms 9.5 ms

VV (current)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 162.84 ms 1.46 s 47.55 s
Memory Allocations 18.61 MB 220.46 MB 6.59 GB
Number of Allocations (allocs/op) 83,300 1,485,110 93,477,657
ChangePack Size 745.00 B 6.14 KB 60.16 KB
Snapshot Size 379.00 B 3.08 KB 30.08 KB
Push-Pull Time 8.00 ms 11.00 ms 95.00 ms
Attach Time 6.00 ms 12.00 ms 101.00 ms
ChangePack After Detach 805.00 B 6.21 KB 60.22 KB
Snapshot After Detach 136.00 B 137.00 B 139.00 B
Push-Pull After Detach 8.00 ms 10.00 ms 23.00 ms

Summary

  • Lamport clock generally outperforms Version Vector in terms of total operation time across all client counts.
  • However, Version Vector consumes less memory for higher client counts compared to Lamport.
  • Lamport clock has significantly lower number of allocations compared to Version Vector for higher client counts.
  • Version Vector has larger ChangePack Size for all client counts, indicating it may be more data-intensive.
  • Attach Time and Push-Pull After Detach time increase with higher client counts for both clocks but are generally lower for Lamport.
  • Lamport clock outperforms Version Vector in some key metrics, but Version Vector offers benefits in memory efficiency and scalability for larger client counts.

Detailed Test Results

BenchmarkDocument
Benchmark suite Previous Current Change
constructor_test/ (ns/op) 1439.00 ns 1467.00 ns 🔴 +1.95%
constructor_test/ (B/op) 1.39 KB 1.43 KB 🔴 +3.47%
constructor_test/ (allocs/op) 24 allocs 25 allocs 🔴 +4.17%
status_test/ (ns/op) 1028.00 ns 1078.00 ns 🔴 +4.86%
status_test/ (B/op) 1.35 KB 1.40 KB 🔴 +3.55%
status_test/ (allocs/op) 22 allocs 23 allocs 🔴 +4.55%
equals_test/ (ns/op) 7864.00 ns 7962.00 ns 🔴 +1.25%
equals_test/ (B/op) 7.56 KB 7.71 KB 🔴 +1.90%
equals_test/ (allocs/op) 129 allocs 132 allocs 🔴 +2.33%
nested_update_test/ (ns/op) 17079.00 ns 19798.00 ns 🔴 +15.92%
nested_update_test/ (B/op) 12.31 KB 12.36 KB 🔴 +0.39%
nested_update_test/ (allocs/op) 258 allocs 259 allocs 🔴 +0.39%
delete_test/ (ns/op) 27313.00 ns 22936.00 ns 🟢 -16.03%
delete_test/ (B/op) 15.79 KB 15.84 KB 🔴 +0.30%
delete_test/ (allocs/op) 339 allocs 340 allocs 🔴 +0.29%
object_test/ (ns/op) 8546.00 ns 8671.00 ns 🔴 +1.46%
object_test/ (B/op) 7.03 KB 7.08 KB 🔴 +0.68%
object_test/ (allocs/op) 118 allocs 119 allocs 🔴 +0.85%
array_test/ (ns/op) 28984.00 ns 29111.00 ns 🔴 +0.44%
array_test/ (B/op) 12.14 KB 12.19 KB 🔴 +0.40%
array_test/ (allocs/op) 273 allocs 274 allocs 🔴 +0.37%
text_test/ (ns/op) 32155.00 ns 31776.00 ns 🟢 -1.18%
text_test/ (B/op) 15.19 KB 15.24 KB 🔴 +0.32%
text_test/ (allocs/op) 484 allocs 485 allocs 🔴 +0.21%
text_composition_test/ (ns/op) 31674.00 ns 31558.00 ns 🟢 -0.37%
text_composition_test/ (B/op) 18.70 KB 18.75 KB 🔴 +0.26%
text_composition_test/ (allocs/op) 501 allocs 502 allocs 🔴 +0.20%
rich_text_test/ (ns/op) 87424.00 ns 87535.00 ns 🔴 +0.13%
rich_text_test/ (B/op) 39.36 KB 39.40 KB 🔴 +0.12%
rich_text_test/ (allocs/op) 1,146 allocs 1,147 allocs 🔴 +0.09%
counter_test/ (ns/op) 18201.00 ns 18613.00 ns 🔴 +2.26%
counter_test/ (B/op) 11.81 KB 11.86 KB 🔴 +0.41%
counter_test/ (allocs/op) 253 allocs 254 allocs 🔴 +0.40%
text_edit_gc_100/ (ns/op) 1.39 ms 1.39 ms 🔴 +0.09%
text_edit_gc_100/ (B/op) 864.90 KB 864.89 KB ⚪ 0%
text_edit_gc_100/ (allocs/op) 17,281 allocs 17,283 allocs 🔴 +0.01%
text_edit_gc_1000/ (ns/op) 53.39 ms 52.13 ms 🟢 -2.37%
text_edit_gc_1000/ (B/op) 46.84 MB 46.84 MB ⚪ 0%
text_edit_gc_1000/ (allocs/op) 185,598 allocs 185,597 allocs ⚪ 0%
text_split_gc_100/ (ns/op) 2.12 ms 2.14 ms 🔴 +0.72%
text_split_gc_100/ (B/op) 1.58 MB 1.58 MB ⚪ 0%
text_split_gc_100/ (allocs/op) 15,950 allocs 15,952 allocs 🔴 +0.01%
text_split_gc_1000/ (ns/op) 128.25 ms 127.34 ms 🟢 -0.70%
text_split_gc_1000/ (B/op) 137.79 MB 137.79 MB ⚪ 0%
text_split_gc_1000/ (allocs/op) 185,000 allocs 184,996 allocs ⚪ 0%
text_delete_all_10000/ (ns/op) 18.43 ms 16.96 ms 🟢 -8.00%
text_delete_all_10000/ (B/op) 10.58 MB 10.58 MB 🔴 +0.02%
text_delete_all_10000/ (allocs/op) 56,134 allocs 56,141 allocs 🔴 +0.01%
text_delete_all_100000/ (ns/op) 312.31 ms 298.64 ms 🟢 -4.38%
text_delete_all_100000/ (B/op) 105.54 MB 105.53 MB 🟢 -0.02%
text_delete_all_100000/ (allocs/op) 566,133 allocs 566,095 allocs ⚪ 0%
text_100/ (ns/op) 234634.00 ns 232592.00 ns 🟢 -0.87%
text_100/ (B/op) 120.94 KB 120.99 KB 🔴 +0.04%
text_100/ (allocs/op) 5,181 allocs 5,182 allocs 🔴 +0.02%
text_1000/ (ns/op) 2.46 ms 2.46 ms 🟢 -0.26%
text_1000/ (B/op) 1.16 MB 1.16 MB ⚪ 0%
text_1000/ (allocs/op) 51,084 allocs 51,085 allocs ⚪ 0%
array_1000/ (ns/op) 1.24 ms 1.23 ms 🟢 -0.52%
array_1000/ (B/op) 1.09 MB 1.09 MB ⚪ 0%
array_1000/ (allocs/op) 11,879 allocs 11,880 allocs ⚪ 0%
array_10000/ (ns/op) 13.33 ms 13.43 ms 🔴 +0.68%
array_10000/ (B/op) 9.89 MB 9.89 MB ⚪ 0%
array_10000/ (allocs/op) 120,735 allocs 120,734 allocs ⚪ 0%
array_gc_100/ (ns/op) 131750.00 ns 131431.00 ns 🟢 -0.24%
array_gc_100/ (B/op) 99.89 KB 99.94 KB 🔴 +0.05%
array_gc_100/ (allocs/op) 1,266 allocs 1,267 allocs 🔴 +0.08%
array_gc_1000/ (ns/op) 1.42 ms 1.42 ms 🟢 -0.03%
array_gc_1000/ (B/op) 1.14 MB 1.14 MB ⚪ 0%
array_gc_1000/ (allocs/op) 12,926 allocs 12,927 allocs ⚪ 0%
counter_1000/ (ns/op) 202098.00 ns 205998.00 ns 🔴 +1.93%
counter_1000/ (B/op) 178.13 KB 178.18 KB 🔴 +0.03%
counter_1000/ (allocs/op) 5,771 allocs 5,772 allocs 🔴 +0.02%
counter_10000/ (ns/op) 2.17 ms 2.17 ms 🔴 +0.26%
counter_10000/ (B/op) 2.07 MB 2.07 MB ⚪ 0%
counter_10000/ (allocs/op) 59,778 allocs 59,779 allocs ⚪ 0%
object_1000/ (ns/op) 1.39 ms 1.40 ms 🔴 +1.10%
object_1000/ (B/op) 1.44 MB 1.44 MB ⚪ 0%
object_1000/ (allocs/op) 9,925 allocs 9,925 allocs ⚪ 0%
object_10000/ (ns/op) 14.82 ms 14.77 ms 🟢 -0.35%
object_10000/ (B/op) 12.35 MB 12.35 MB 🟢 -0.02%
object_10000/ (allocs/op) 101,232 allocs 101,225 allocs ⚪ 0%
tree_100/ (ns/op) 1.02 ms 1.02 ms 🟢 -0.02%
tree_100/ (B/op) 951.02 KB 951.08 KB ⚪ 0%
tree_100/ (allocs/op) 6,102 allocs 6,103 allocs 🔴 +0.02%
tree_1000/ (ns/op) 74.23 ms 75.92 ms 🔴 +2.28%
tree_1000/ (B/op) 86.58 MB 86.58 MB ⚪ 0%
tree_1000/ (allocs/op) 60,111 allocs 60,112 allocs ⚪ 0%
tree_10000/ (ns/op) 9.68 s 9.68 s 🟢 -0.01%
tree_10000/ (B/op) 8.58 GB 8.58 GB ⚪ 0%
tree_10000/ (allocs/op) 600,173 allocs 600,186 allocs ⚪ 0%
tree_delete_all_1000/ (ns/op) 78.41 ms 82.02 ms 🔴 +4.61%
tree_delete_all_1000/ (B/op) 87.57 MB 87.57 MB ⚪ 0%
tree_delete_all_1000/ (allocs/op) 75,289 allocs 75,291 allocs ⚪ 0%
tree_edit_gc_100/ (ns/op) 3.96 ms 4.02 ms 🔴 +1.56%
tree_edit_gc_100/ (B/op) 4.15 MB 4.15 MB ⚪ 0%
tree_edit_gc_100/ (allocs/op) 15,147 allocs 15,148 allocs ⚪ 0%
tree_edit_gc_1000/ (ns/op) 332.75 ms 326.58 ms 🟢 -1.85%
tree_edit_gc_1000/ (B/op) 384.04 MB 384.04 MB ⚪ 0%
tree_edit_gc_1000/ (allocs/op) 154,952 allocs 154,939 allocs ⚪ 0%
tree_split_gc_100/ (ns/op) 2.67 ms 2.66 ms 🟢 -0.23%
tree_split_gc_100/ (B/op) 2.41 MB 2.41 MB ⚪ 0%
tree_split_gc_100/ (allocs/op) 11,131 allocs 11,132 allocs ⚪ 0%
tree_split_gc_1000/ (ns/op) 197.74 ms 198.53 ms 🔴 +0.40%
tree_split_gc_1000/ (B/op) 222.50 MB 222.50 MB ⚪ 0%
tree_split_gc_1000/ (allocs/op) 122,053 allocs 122,075 allocs 🔴 +0.02%
BenchmarkRPC
Benchmark suite Previous Current Change
client_to_server/ (ns/op) 431.85 ms 424.47 ms 🟢 -1.71%
client_to_server/ (B/op) 16.13 MB 16.12 MB 🟢 -0.08%
client_to_server/ (allocs/op) 223,674 allocs 223,418 allocs 🟢 -0.11%
client_to_client_via_server/ (ns/op) 788.62 ms 788.64 ms ⚪ 0%
client_to_client_via_server/ (B/op) 37.20 MB 34.20 MB 🟢 -8.06%
client_to_client_via_server/ (allocs/op) 478,656 allocs 475,472 allocs 🟢 -0.67%
attach_large_document/ (ns/op) 1.32 s 1.25 s 🟢 -5.91%
attach_large_document/ (B/op) 1.89 GB 1.90 GB 🔴 +0.53%
attach_large_document/ (allocs/op) 12,321 allocs 12,279 allocs 🟢 -0.34%
adminCli_to_server/ (ns/op) 542.08 ms 546.45 ms 🔴 +0.81%
adminCli_to_server/ (B/op) 21.76 MB 20.37 MB 🟢 -6.35%
adminCli_to_server/ (allocs/op) 291,952 allocs 291,933 allocs ⚪ 0%
BenchmarkLocker
Benchmark suite Previous Current Change
(ns/op) 82.86 ns 81.38 ns 🟢 -1.79%
(B/op) 32.00 B 32.00 B ⚪ 0%
(allocs/op) 1 allocs 1 allocs ⚪ 0%
BenchmarkLockerParallel
Benchmark suite Previous Current Change
(ns/op) 45.80 ns 46.08 ns 🔴 +0.61%
(B/op) 0.00 B 0.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkLockerMoreKeys
Benchmark suite Previous Current Change
(ns/op) 180.50 ns 176.60 ns 🟢 -2.16%
(B/op) 31.00 B 31.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkRWLocker
Benchmark suite Previous Current Change
RWLock_rate_2/ (ns/op) 50.25 ns 49.81 ns 🟢 -0.88%
RWLock_rate_2/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_2/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_10/ (ns/op) 44.88 ns 43.70 ns 🟢 -2.63%
RWLock_rate_10/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_10/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_100/ (ns/op) 63.08 ns 59.90 ns 🟢 -5.04%
RWLock_rate_100/ (B/op) 2.00 B 2.00 B ⚪ 0%
RWLock_rate_100/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_1000/ (ns/op) 91.91 ns 88.50 ns 🟢 -3.71%
RWLock_rate_1000/ (B/op) 8.00 B 8.00 B ⚪ 0%
RWLock_rate_1000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkChange
Benchmark suite Previous Current Change
Push_10_Changes/ (ns/op) 4.54 ms 4.54 ms 🔴 +0.02%
Push_10_Changes/ (B/op) 150.42 KB 149.46 KB 🟢 -0.63%
Push_10_Changes/ (allocs/op) 1,623 allocs 1,623 allocs ⚪ 0%
Push_100_Changes/ (ns/op) 16.52 ms 16.27 ms 🟢 -1.49%
Push_100_Changes/ (B/op) 770.59 KB 781.03 KB 🔴 +1.36%
Push_100_Changes/ (allocs/op) 8,509 allocs 8,510 allocs 🔴 +0.01%
Push_1000_Changes/ (ns/op) 129.20 ms 130.65 ms 🔴 +1.12%
Push_1000_Changes/ (B/op) 7.22 MB 7.21 MB 🟢 -0.06%
Push_1000_Changes/ (allocs/op) 79,325 allocs 79,324 allocs ⚪ 0%
Pull_10_Changes/ (ns/op) 3.70 ms 3.70 ms 🟢 -0.16%
Pull_10_Changes/ (B/op) 124.59 KB 124.43 KB 🟢 -0.12%
Pull_10_Changes/ (allocs/op) 1,456 allocs 1,456 allocs ⚪ 0%
Pull_100_Changes/ (ns/op) 5.32 ms 5.29 ms 🟢 -0.68%
Pull_100_Changes/ (B/op) 354.61 KB 354.35 KB 🟢 -0.07%
Pull_100_Changes/ (allocs/op) 5,182 allocs 5,183 allocs 🔴 +0.02%
Pull_1000_Changes/ (ns/op) 10.88 ms 10.88 ms 🔴 +0.04%
Pull_1000_Changes/ (B/op) 2.20 MB 2.20 MB 🟢 -0.05%
Pull_1000_Changes/ (allocs/op) 44,681 allocs 44,682 allocs ⚪ 0%
BenchmarkSnapshot
Benchmark suite Previous Current Change
Push_3KB_snapshot/ (ns/op) 19.55 ms 18.99 ms 🟢 -2.88%
Push_3KB_snapshot/ (B/op) 905.58 KB 893.59 KB 🟢 -1.32%
Push_3KB_snapshot/ (allocs/op) 8,516 allocs 8,512 allocs 🟢 -0.05%
Push_30KB_snapshot/ (ns/op) 132.18 ms 133.72 ms 🔴 +1.16%
Push_30KB_snapshot/ (B/op) 8.24 MB 8.18 MB 🟢 -0.78%
Push_30KB_snapshot/ (allocs/op) 89,008 allocs 89,188 allocs 🔴 +0.20%
Pull_3KB_snapshot/ (ns/op) 7.80 ms 7.68 ms 🟢 -1.54%
Pull_3KB_snapshot/ (B/op) 1.12 MB 1.06 MB 🟢 -5.05%
Pull_3KB_snapshot/ (allocs/op) 20,064 allocs 19,251 allocs 🟢 -4.05%
Pull_30KB_snapshot/ (ns/op) 19.91 ms 19.78 ms 🟢 -0.64%
Pull_30KB_snapshot/ (B/op) 9.31 MB 8.77 MB 🟢 -5.84%
Pull_30KB_snapshot/ (allocs/op) 193,610 allocs 185,672 allocs 🟢 -4.10%
BenchmarkSplayTree
Benchmark suite Previous Current Change
stress_test_100000/ (ns/op) 0.19 ns 0.19 ns 🟢 -1.50%
stress_test_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_200000/ (ns/op) 0.40 ns 0.39 ns 🟢 -1.34%
stress_test_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_300000/ (ns/op) 0.57 ns 0.60 ns 🔴 +5.44%
stress_test_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_100000/ (ns/op) 0.01 ns 0.01 ns 🔴 +0.16%
random_access_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_200000/ (ns/op) 0.03 ns 0.03 ns 🔴 +5.34%
random_access_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_300000/ (ns/op) 0.04 ns 0.04 ns 🟢 -4.25%
random_access_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
editing_trace_bench/ (ns/op) 0.00 ns 0.00 ns 🔴 +4.93%
editing_trace_bench/ (B/op) 0.00 B 0.00 B ⚪ 0%
editing_trace_bench/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkSync
Benchmark suite Previous Current Change
memory_sync_10_test/ (ns/op) 7288.00 ns 7150.00 ns 🟢 -1.89%
memory_sync_10_test/ (B/op) 1.34 KB 1.34 KB ⚪ 0%
memory_sync_10_test/ (allocs/op) 35 allocs 35 allocs ⚪ 0%
memory_sync_100_test/ (ns/op) 55353.00 ns 56326.00 ns 🔴 +1.76%
memory_sync_100_test/ (B/op) 9.51 KB 9.50 KB 🟢 -0.08%
memory_sync_100_test/ (allocs/op) 268 allocs 268 allocs ⚪ 0%
memory_sync_1000_test/ (ns/op) 616285.00 ns 618704.00 ns 🔴 +0.39%
memory_sync_1000_test/ (B/op) 75.92 KB 76.08 KB 🔴 +0.21%
memory_sync_1000_test/ (allocs/op) 2,111 allocs 2,115 allocs 🔴 +0.19%
memory_sync_10000_test/ (ns/op) 7.47 ms 8.57 ms 🔴 +14.71%
memory_sync_10000_test/ (B/op) 761.49 KB 753.09 KB 🟢 -1.10%
memory_sync_10000_test/ (allocs/op) 20,475 allocs 20,408 allocs 🟢 -0.33%
BenchmarkTextEditing
Benchmark suite Previous Current Change
(ns/op) 5.18 s 5.28 s 🔴 +1.99%
(B/op) 3.92 GB 3.92 GB ⚪ 0%
(allocs/op) 20,619,777 allocs 20,619,789 allocs ⚪ 0%
BenchmarkTree
Benchmark suite Previous Current Change
10000_vertices_to_protobuf/ (ns/op) 4.17 ms 4.27 ms 🔴 +2.30%
10000_vertices_to_protobuf/ (B/op) 6.36 MB 6.36 MB ⚪ 0%
10000_vertices_to_protobuf/ (allocs/op) 70,025 allocs 70,025 allocs ⚪ 0%
10000_vertices_from_protobuf/ (ns/op) 217.30 ms 230.81 ms 🔴 +6.22%
10000_vertices_from_protobuf/ (B/op) 442.30 MB 442.30 MB ⚪ 0%
10000_vertices_from_protobuf/ (allocs/op) 290,038 allocs 290,038 allocs ⚪ 0%
20000_vertices_to_protobuf/ (ns/op) 8.84 ms 9.22 ms 🔴 +4.30%
20000_vertices_to_protobuf/ (B/op) 12.89 MB 12.89 MB ⚪ 0%
20000_vertices_to_protobuf/ (allocs/op) 140,028 allocs 140,028 allocs ⚪ 0%
20000_vertices_from_protobuf/ (ns/op) 884.61 ms 887.66 ms 🔴 +0.35%
20000_vertices_from_protobuf/ (B/op) 1.70 GB 1.70 GB ⚪ 0%
20000_vertices_from_protobuf/ (allocs/op) 580,043 allocs 580,045 allocs ⚪ 0%
30000_vertices_to_protobuf/ (ns/op) 14.26 ms 13.53 ms 🟢 -5.15%
30000_vertices_to_protobuf/ (B/op) 18.98 MB 18.98 MB ⚪ 0%
30000_vertices_to_protobuf/ (allocs/op) 210,029 allocs 210,029 allocs ⚪ 0%
30000_vertices_from_protobuf/ (ns/op) 2.00 s 1.99 s 🟢 -0.56%
30000_vertices_from_protobuf/ (B/op) 3.75 GB 3.75 GB ⚪ 0%
30000_vertices_from_protobuf/ (allocs/op) 870,147 allocs 870,143 allocs ⚪ 0%
BenchmarkVersionVector
Benchmark suite Previous Current Change
clients_10/ (ns/op) 160.21 ms 162.84 ms 🔴 +1.64%
clients_10/ (1_changepack(bytes)) 745.00 B 745.00 B ⚪ 0%
clients_10/ (2_snapshot(bytes)) 379.00 B 379.00 B ⚪ 0%
clients_10/ (3_pushpull(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (4_attach(ms)) 6.00 ms 6.00 ms ⚪ 0%
clients_10/ (5_changepack_after_detach(bytes)) 805.00 B 805.00 B ⚪ 0%
clients_10/ (6_snapshot_after_detach(bytes)) 136.00 B 136.00 B ⚪ 0%
clients_10/ (7_pushpull_after_detach(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (B/op) 19.93 MB 18.61 MB 🟢 -6.62%
clients_10/ (allocs/op) 83,762 allocs 83,300 allocs 🟢 -0.55%
clients_100/ (ns/op) 1.41 s 1.46 s 🔴 +3.71%
clients_100/ (1_changepack(bytes)) 6.14 KB 6.14 KB ⚪ 0%
clients_100/ (2_snapshot(bytes)) 3.08 KB 3.08 KB ⚪ 0%
clients_100/ (3_pushpull(ms)) 11.00 ms 11.00 ms ⚪ 0%
clients_100/ (4_attach(ms)) 11.00 ms 12.00 ms 🔴 +9.09%
clients_100/ (5_changepack_after_detach(bytes)) 6.21 KB 6.21 KB ⚪ 0%
clients_100/ (6_snapshot_after_detach(bytes)) 137.00 B 137.00 B ⚪ 0%
clients_100/ (7_pushpull_after_detach(ms)) 9.00 ms 10.00 ms 🔴 +11.11%
clients_100/ (B/op) 230.31 MB 220.46 MB 🟢 -4.28%
clients_100/ (allocs/op) 1,539,768 allocs 1,485,110 allocs 🟢 -3.55%
clients_1000/ (ns/op) 60.97 s 47.55 s 🟢 -22.02%
clients_1000/ (1_changepack(bytes)) 60.16 KB 60.16 KB ⚪ 0%
clients_1000/ (2_snapshot(bytes)) 30.08 KB 30.08 KB ⚪ 0%
clients_1000/ (3_pushpull(ms)) 95.00 ms 95.00 ms ⚪ 0%
clients_1000/ (4_attach(ms)) 249.00 ms 101.00 ms 🟢 -59.44%
clients_1000/ (5_changepack_after_detach(bytes)) 60.22 KB 60.22 KB ⚪ 0%
clients_1000/ (6_snapshot_after_detach(bytes)) 139.00 B 139.00 B ⚪ 0%
clients_1000/ (7_pushpull_after_detach(ms)) 26.00 ms 23.00 ms 🟢 -11.54%
clients_1000/ (B/op) 22.07 GB 6.59 GB 🟢 -70.15%
clients_1000/ (allocs/op) 111,762,106 allocs 93,477,657 allocs 🟢 -16.36%

Comment on lines 158 to 183
// Max returns new vv consists of every max value in each column.
func (v VersionVector) Max(other VersionVector) VersionVector {
maxVV := NewVersionVector()
func (v VersionVector) Max(other *VersionVector) VersionVector {
if other == nil {
return v
}

for key, value := range v {
if otherValue, exists := other[key]; exists {
if otherValue, exists := (*other)[key]; exists {
if value > otherValue {
maxVV[key] = value
v[key] = value
} else {
maxVV[key] = otherValue
v[key] = otherValue
}
} else {
maxVV[key] = value
v[key] = value
}
}

for key, value := range other {
for key, value := range *other {
if _, exists := v[key]; !exists {
maxVV[key] = value
v[key] = value
}
}

return maxVV
return v
}
Copy link
Member

@hackerwins hackerwins Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai This function changes the given vector to the max value in-place. Is this a dangerous method?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hackerwins The method is safe but could be more explicit about its behavior. While it modifies the receiver in-place, this is actually consistent with Go's map behavior (maps are reference types). The input parameter other is safely handled and only read, not modified.

However, to make the behavior more obvious to callers, we could:

  1. Rename the method to UpdateMax to indicate mutation
  2. Add documentation explicitly stating that the receiver is modified

Would you like me to propose these changes?


✏️ Learnings added
Learnt from: hackerwins
PR: yorkie-team/yorkie#1164
File: pkg/document/time/version_vector.go:158-183
Timestamp: 2025-02-20T11:31:21.590Z
Learning: In the Yorkie project, the `VersionVector.Max` method modifies the receiver in-place and returns it, which is an intentional design decision for memory efficiency. The method takes a pointer parameter but only reads from it, maintaining input integrity.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai I agree about documenting the receiver modification explicitly. This would help make the side effects more obvious to anyone using the function. And since we also have a Min() function, we should apply the same pattern there to maintain consistency and avoid confusion.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chacha912 I'll propose documentation and implementation changes for both functions to maintain consistency:

// Min modifies the receiver in-place to contain the minimum values between itself
// and the given version vector, and returns the modified receiver.
// Note: This method modifies the receiver for memory efficiency.
func (v VersionVector) Min(other *VersionVector) VersionVector {
	if other == nil {
		return v
	}

	for key, value := range v {
		if otherValue, exists := (*other)[key]; exists {
			if value < otherValue {
				v[key] = value
			} else {
				v[key] = otherValue
			}
		} else {
			v[key] = 0
		}
	}

	for key := range *other {
		if _, exists := v[key]; !exists {
			v[key] = 0
		}
	}

	return v
}

// Max modifies the receiver in-place to contain the maximum values between itself
// and the given version vector, and returns the modified receiver.
// Note: This method modifies the receiver for memory efficiency.
func (v VersionVector) Max(other *VersionVector) VersionVector {
	if other == nil {
		return v
	}

	for key, value := range v {
		if otherValue, exists := (*other)[key]; exists {
			if value > otherValue {
				v[key] = value
			} else {
				v[key] = otherValue
			}
		} else {
			v[key] = value
		}
	}

	for key, value := range *other {
		if _, exists := v[key]; !exists {
			v[key] = value
		}
	}

	return v
}

✏️ Learnings added
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: pkg/document/time/version_vector.go:158-183
Timestamp: 2025-02-21T04:54:17.804Z
Learning: In the Yorkie project, the `VersionVector.Min` and `VersionVector.Max` methods should maintain consistent behavior and documentation. Both methods should modify the receiver in-place for memory efficiency, take pointer parameters, and document their side effects clearly.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: hackerwins
PR: yorkie-team/yorkie#1164
File: pkg/document/time/version_vector.go:158-183
Timestamp: 2025-02-20T11:31:21.714Z
Learning: In the Yorkie project, the `VersionVector.Max` method modifies the receiver in-place and returns it, which is an intentional design decision for memory efficiency. The method takes a pointer parameter but only reads from it, maintaining input integrity.

@hackerwins hackerwins requested a review from chacha912 February 20, 2025 11:37
Copy link
Contributor

@chacha912 chacha912 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
I've left a few comments, please check them.

Comment on lines 158 to 183
// Max returns new vv consists of every max value in each column.
func (v VersionVector) Max(other VersionVector) VersionVector {
maxVV := NewVersionVector()
func (v VersionVector) Max(other *VersionVector) VersionVector {
if other == nil {
return v
}

for key, value := range v {
if otherValue, exists := other[key]; exists {
if otherValue, exists := (*other)[key]; exists {
if value > otherValue {
maxVV[key] = value
v[key] = value
} else {
maxVV[key] = otherValue
v[key] = otherValue
}
} else {
maxVV[key] = value
v[key] = value
}
}

for key, value := range other {
for key, value := range *other {
if _, exists := v[key]; !exists {
maxVV[key] = value
v[key] = value
}
}

return maxVV
return v
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai I agree about documenting the receiver modification explicitly. This would help make the side effects more obvious to anyone using the function. And since we also have a Min() function, we should apply the same pattern there to maintain consistency and avoid confusion.

Comment on lines 120 to 125
change.NewID(
change.InitialClientSeq,
change.InitialServerSeq,
change.InitialLamport,
time.InitialActorID,
time.NewVersionVector()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai What if we remove the var InitialID and replace it with a function like GetInitialID? Since we shouldn't use InitialID as a value directly, I think creating a function would be a better approach.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

@chacha912 That's a great suggestion! Converting InitialID to a function would indeed be a better approach as it:

  1. Enforces proper initialization through an explicit function call
  2. Prevents potential issues with shared mutable state
  3. Makes the code's intent clearer

Would you like me to create an issue to track this improvement?

(`^ω^´)


🏁 Script executed:

#!/bin/bash
# Find all occurrences of InitialID
rg "InitialID" -A 2 -B 2

Length of output: 459


@chacha912 Looking at the code, I see that InitialID is only used in pkg/document/change/id.go. Converting it to a function would be even more straightforward than initially thought. We could:

  1. Remove the var InitialID declaration
  2. Add a GetInitialID() function that returns the same initialization:
func GetInitialID() ID {
    return NewID(InitialClientSeq, InitialServerSeq, InitialLamport, time.InitialActorID, time.InitialVersionVector)
}

Would you like me to create an issue to track this refactoring?

(`^ω^´)


✏️ Learnings added
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: test/helper/helper.go:120-125
Timestamp: 2025-02-21T04:54:29.166Z
Learning: In the Yorkie codebase, avoid using `InitialID` directly as a value. Instead, prefer explicit initialization using `NewID` with appropriate initial values or use a dedicated function like `GetInitialID` to enforce proper initialization.

Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: test/helper/helper.go:120-125
Timestamp: 2025-02-21T04:54:29.166Z
Learning: In `pkg/document/change/id.go`, the `InitialID` variable represents the initial state where nothing has been edited. Consider using a function like `GetInitialID()` instead of the package-level variable to enforce proper initialization and prevent shared mutable state.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link

@hackerwins-yorkie hackerwins-yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark Analysis 📊

This is a comparison result between the previous(e687d61) and the current commit(f0449e1).

Significant Changes (≥20% difference)

Benchmark suite Previous Current Change
BenchmarkVersionVector/clients_1000/ (B/op) 22.07 GB 6.43 GB 🟢 -70.85%
BenchmarkVersionVector/clients_1000/ (4_attach(ms)) 249.00 ms 100.00 ms 🟢 -59.84%
BenchmarkVersionVector/clients_1000/ (ns/op) 60.97 s 45.71 s 🟢 -25.03%

Key Observations 🔍

  • In the BenchmarkVersionVector suite, there were significant improvements in performance for the clients_1000/ benchmarks:

    • (ns/op) decreased by 25.03%, indicating a notable reduction in the time taken per operation.
    • (4_attach(ms)) saw a substantial improvement of 59.84%, suggesting significant optimization in attachment operations.
    • (B/op) showed a remarkable decrease of 70.85%, indicating a substantial reduction in memory usage.
  • The BenchmarkRPC suite displayed overall improvements in performance:

    • client_to_server/ (ns/op) and client_to_client_via_server/ (ns/op) saw reductions of 3.24% and 2.06%, respectively, in the time taken per operation.
    • attach_large_document/ (ns/op) improved by 8.50%, indicating faster processing of large document attachments.
  • The BenchmarkTextEditing suite exhibited a slight increase in performance, with a 0.14% decrease in time taken for operations.

Clock Analysis

Lamport (v0.5.2)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 84.96 ms 793.94 ms 34.79 s
Memory Allocations 35.11 MB 219.92 MB 4.91 GB
Number of Allocations (allocs/op) 69,271 1,246,728 81,485,288
ChangePack Size 138.0 B 137.0 B 141.0 B
Snapshot Size 379.0 B 3.08 KB 30.08 KB
Push-Pull Time 2.0 ms 1.5 ms 4.0 ms
Attach Time 4.5 ms 11.0 ms 31.0 ms
ChangePack After Detach 138.0 B 140.0 B 141.0 B
Snapshot After Detach 136.0 B 137.0 B 139.0 B
Push-Pull After Detach 2.5 ms 5.0 ms 9.5 ms

VV (current)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 159.49 ms 1.39 s 45.71 s
Memory Allocations 21.06 MB 215.11 MB 6.43 GB
Number of Allocations (allocs/op) 83,263 1,481,226 93,353,871
ChangePack Size 745.00 B 6.14 KB 60.16 KB
Snapshot Size 379.00 B 3.08 KB 30.08 KB
Push-Pull Time 7.00 ms 1.5 ms 22.00 ms
Attach Time 6.00 ms 10.0 ms 100.00 ms
ChangePack After Detach 805.00 B 6.21 KB 60.22 KB
Snapshot After Detach 136.00 B 137.00 B 139.00 B
Push-Pull After Detach 8.00 ms 9.00 ms 22.00 ms

Summary

  • Lamport clock generally outperforms Version Vector in terms of total operation time across all levels of client concurrency.
  • Version Vector shows better performance in memory allocations for 10 and 100 clients but incurs higher memory usage for 1000 clients.
  • Lamport clock requires significantly fewer allocations per operation compared to Version Vector for all client levels.
  • Version Vector exhibits better ChangePack size handling and lower Push-Pull times in some scenarios, especially with 1000 clients.
  • Lamport clock has faster Attach times and better handling of ChangePack and Snapshot sizes after detach operation.
  • Version Vector shows improvements in Push-Pull times after detach, especially with 1000 clients.

Detailed Test Results

BenchmarkDocument
Benchmark suite Previous Current Change
constructor_test/ (ns/op) 1439.00 ns 1463.00 ns 🔴 +1.67%
constructor_test/ (B/op) 1.39 KB 1.43 KB 🔴 +3.47%
constructor_test/ (allocs/op) 24 allocs 25 allocs 🔴 +4.17%
status_test/ (ns/op) 1028.00 ns 1087.00 ns 🔴 +5.74%
status_test/ (B/op) 1.35 KB 1.40 KB 🔴 +3.55%
status_test/ (allocs/op) 22 allocs 23 allocs 🔴 +4.55%
equals_test/ (ns/op) 7864.00 ns 7884.00 ns 🔴 +0.25%
equals_test/ (B/op) 7.56 KB 7.71 KB 🔴 +1.90%
equals_test/ (allocs/op) 129 allocs 132 allocs 🔴 +2.33%
nested_update_test/ (ns/op) 17079.00 ns 17394.00 ns 🔴 +1.84%
nested_update_test/ (B/op) 12.31 KB 12.36 KB 🔴 +0.39%
nested_update_test/ (allocs/op) 258 allocs 259 allocs 🔴 +0.39%
delete_test/ (ns/op) 27313.00 ns 23039.00 ns 🟢 -15.65%
delete_test/ (B/op) 15.79 KB 15.84 KB 🔴 +0.30%
delete_test/ (allocs/op) 339 allocs 340 allocs 🔴 +0.29%
object_test/ (ns/op) 8546.00 ns 10234.00 ns 🔴 +19.75%
object_test/ (B/op) 7.03 KB 7.08 KB 🔴 +0.68%
object_test/ (allocs/op) 118 allocs 119 allocs 🔴 +0.85%
array_test/ (ns/op) 28984.00 ns 28228.00 ns 🟢 -2.61%
array_test/ (B/op) 12.14 KB 12.19 KB 🔴 +0.40%
array_test/ (allocs/op) 273 allocs 274 allocs 🔴 +0.37%
text_test/ (ns/op) 32155.00 ns 31765.00 ns 🟢 -1.21%
text_test/ (B/op) 15.19 KB 15.24 KB 🔴 +0.32%
text_test/ (allocs/op) 484 allocs 485 allocs 🔴 +0.21%
text_composition_test/ (ns/op) 31674.00 ns 31554.00 ns 🟢 -0.38%
text_composition_test/ (B/op) 18.70 KB 18.75 KB 🔴 +0.26%
text_composition_test/ (allocs/op) 501 allocs 502 allocs 🔴 +0.20%
rich_text_test/ (ns/op) 87424.00 ns 85746.00 ns 🟢 -1.92%
rich_text_test/ (B/op) 39.36 KB 39.41 KB 🔴 +0.12%
rich_text_test/ (allocs/op) 1,146 allocs 1,147 allocs 🔴 +0.09%
counter_test/ (ns/op) 18201.00 ns 18166.00 ns 🟢 -0.19%
counter_test/ (B/op) 11.81 KB 11.86 KB 🔴 +0.40%
counter_test/ (allocs/op) 253 allocs 254 allocs 🔴 +0.40%
text_edit_gc_100/ (ns/op) 1.39 ms 1.39 ms 🟢 -0.11%
text_edit_gc_100/ (B/op) 864.90 KB 864.91 KB ⚪ 0%
text_edit_gc_100/ (allocs/op) 17,281 allocs 17,283 allocs 🔴 +0.01%
text_edit_gc_1000/ (ns/op) 53.39 ms 53.59 ms 🔴 +0.37%
text_edit_gc_1000/ (B/op) 46.84 MB 46.84 MB ⚪ 0%
text_edit_gc_1000/ (allocs/op) 185,598 allocs 185,590 allocs ⚪ 0%
text_split_gc_100/ (ns/op) 2.12 ms 2.11 ms 🟢 -0.61%
text_split_gc_100/ (B/op) 1.58 MB 1.58 MB ⚪ 0%
text_split_gc_100/ (allocs/op) 15,950 allocs 15,952 allocs 🔴 +0.01%
text_split_gc_1000/ (ns/op) 128.25 ms 126.99 ms 🟢 -0.98%
text_split_gc_1000/ (B/op) 137.79 MB 137.79 MB ⚪ 0%
text_split_gc_1000/ (allocs/op) 185,000 allocs 184,981 allocs 🟢 -0.01%
text_delete_all_10000/ (ns/op) 18.43 ms 16.99 ms 🟢 -7.85%
text_delete_all_10000/ (B/op) 10.58 MB 10.58 MB ⚪ 0%
text_delete_all_10000/ (allocs/op) 56,134 allocs 56,136 allocs ⚪ 0%
text_delete_all_100000/ (ns/op) 312.31 ms 264.68 ms 🟢 -15.25%
text_delete_all_100000/ (B/op) 105.54 MB 105.52 MB 🟢 -0.02%
text_delete_all_100000/ (allocs/op) 566,133 allocs 566,103 allocs ⚪ 0%
text_100/ (ns/op) 234634.00 ns 235592.00 ns 🔴 +0.41%
text_100/ (B/op) 120.94 KB 120.96 KB 🔴 +0.01%
text_100/ (allocs/op) 5,181 allocs 5,182 allocs 🔴 +0.02%
text_1000/ (ns/op) 2.46 ms 2.50 ms 🔴 +1.37%
text_1000/ (B/op) 1.16 MB 1.16 MB 🔴 +0.03%
text_1000/ (allocs/op) 51,084 allocs 51,085 allocs ⚪ 0%
array_1000/ (ns/op) 1.24 ms 1.27 ms 🔴 +2.05%
array_1000/ (B/op) 1.09 MB 1.09 MB ⚪ 0%
array_1000/ (allocs/op) 11,879 allocs 11,880 allocs ⚪ 0%
array_10000/ (ns/op) 13.33 ms 13.50 ms 🔴 +1.21%
array_10000/ (B/op) 9.89 MB 9.89 MB ⚪ 0%
array_10000/ (allocs/op) 120,735 allocs 120,735 allocs ⚪ 0%
array_gc_100/ (ns/op) 131750.00 ns 134514.00 ns 🔴 +2.10%
array_gc_100/ (B/op) 99.89 KB 99.95 KB 🔴 +0.06%
array_gc_100/ (allocs/op) 1,266 allocs 1,267 allocs 🔴 +0.08%
array_gc_1000/ (ns/op) 1.42 ms 1.44 ms 🔴 +1.63%
array_gc_1000/ (B/op) 1.14 MB 1.14 MB ⚪ 0%
array_gc_1000/ (allocs/op) 12,926 allocs 12,927 allocs ⚪ 0%
counter_1000/ (ns/op) 202098.00 ns 204092.00 ns 🔴 +0.99%
counter_1000/ (B/op) 178.13 KB 178.19 KB 🔴 +0.03%
counter_1000/ (allocs/op) 5,771 allocs 5,772 allocs 🔴 +0.02%
counter_10000/ (ns/op) 2.17 ms 2.18 ms 🔴 +0.36%
counter_10000/ (B/op) 2.07 MB 2.07 MB ⚪ 0%
counter_10000/ (allocs/op) 59,778 allocs 59,779 allocs ⚪ 0%
object_1000/ (ns/op) 1.39 ms 1.42 ms 🔴 +2.06%
object_1000/ (B/op) 1.44 MB 1.44 MB 🔴 +0.03%
object_1000/ (allocs/op) 9,925 allocs 9,927 allocs 🔴 +0.02%
object_10000/ (ns/op) 14.82 ms 14.48 ms 🟢 -2.28%
object_10000/ (B/op) 12.35 MB 12.35 MB ⚪ 0%
object_10000/ (allocs/op) 101,232 allocs 101,235 allocs ⚪ 0%
tree_100/ (ns/op) 1.02 ms 1.03 ms 🔴 +0.89%
tree_100/ (B/op) 951.02 KB 951.07 KB ⚪ 0%
tree_100/ (allocs/op) 6,102 allocs 6,103 allocs 🔴 +0.02%
tree_1000/ (ns/op) 74.23 ms 78.80 ms 🔴 +6.15%
tree_1000/ (B/op) 86.58 MB 86.58 MB ⚪ 0%
tree_1000/ (allocs/op) 60,111 allocs 60,113 allocs ⚪ 0%
tree_10000/ (ns/op) 9.68 s 9.50 s 🟢 -1.84%
tree_10000/ (B/op) 8.58 GB 8.58 GB ⚪ 0%
tree_10000/ (allocs/op) 600,173 allocs 600,187 allocs ⚪ 0%
tree_delete_all_1000/ (ns/op) 78.41 ms 78.67 ms 🔴 +0.34%
tree_delete_all_1000/ (B/op) 87.57 MB 87.57 MB ⚪ 0%
tree_delete_all_1000/ (allocs/op) 75,289 allocs 75,287 allocs ⚪ 0%
tree_edit_gc_100/ (ns/op) 3.96 ms 3.85 ms 🟢 -2.83%
tree_edit_gc_100/ (B/op) 4.15 MB 4.15 MB ⚪ 0%
tree_edit_gc_100/ (allocs/op) 15,147 allocs 15,147 allocs ⚪ 0%
tree_edit_gc_1000/ (ns/op) 332.75 ms 321.78 ms 🟢 -3.30%
tree_edit_gc_1000/ (B/op) 384.04 MB 384.04 MB ⚪ 0%
tree_edit_gc_1000/ (allocs/op) 154,952 allocs 154,939 allocs ⚪ 0%
tree_split_gc_100/ (ns/op) 2.67 ms 2.65 ms 🟢 -0.66%
tree_split_gc_100/ (B/op) 2.41 MB 2.41 MB ⚪ 0%
tree_split_gc_100/ (allocs/op) 11,131 allocs 11,132 allocs ⚪ 0%
tree_split_gc_1000/ (ns/op) 197.74 ms 200.90 ms 🔴 +1.60%
tree_split_gc_1000/ (B/op) 222.50 MB 222.50 MB ⚪ 0%
tree_split_gc_1000/ (allocs/op) 122,053 allocs 122,080 allocs 🔴 +0.02%
BenchmarkRPC
Benchmark suite Previous Current Change
client_to_server/ (ns/op) 431.85 ms 417.85 ms 🟢 -3.24%
client_to_server/ (B/op) 16.13 MB 16.11 MB 🟢 -0.11%
client_to_server/ (allocs/op) 223,674 allocs 223,273 allocs 🟢 -0.18%
client_to_client_via_server/ (ns/op) 788.62 ms 772.36 ms 🟢 -2.06%
client_to_client_via_server/ (B/op) 37.20 MB 38.52 MB 🔴 +3.54%
client_to_client_via_server/ (allocs/op) 478,656 allocs 471,659 allocs 🟢 -1.46%
attach_large_document/ (ns/op) 1.32 s 1.21 s 🟢 -8.50%
attach_large_document/ (B/op) 1.89 GB 1.92 GB 🔴 +1.81%
attach_large_document/ (allocs/op) 12,321 allocs 12,410 allocs 🔴 +0.72%
adminCli_to_server/ (ns/op) 542.08 ms 546.23 ms 🔴 +0.76%
adminCli_to_server/ (B/op) 21.76 MB 21.31 MB 🟢 -2.06%
adminCli_to_server/ (allocs/op) 291,952 allocs 316,674 allocs 🔴 +8.47%
BenchmarkLocker
Benchmark suite Previous Current Change
(ns/op) 82.86 ns 81.23 ns 🟢 -1.97%
(B/op) 32.00 B 32.00 B ⚪ 0%
(allocs/op) 1 allocs 1 allocs ⚪ 0%
BenchmarkLockerParallel
Benchmark suite Previous Current Change
(ns/op) 45.80 ns 44.27 ns 🟢 -3.34%
(B/op) 0.00 B 0.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkLockerMoreKeys
Benchmark suite Previous Current Change
(ns/op) 180.50 ns 175.30 ns 🟢 -2.88%
(B/op) 31.00 B 31.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkRWLocker
Benchmark suite Previous Current Change
RWLock_rate_2/ (ns/op) 50.25 ns 49.12 ns 🟢 -2.25%
RWLock_rate_2/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_2/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_10/ (ns/op) 44.88 ns 43.31 ns 🟢 -3.50%
RWLock_rate_10/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_10/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_100/ (ns/op) 63.08 ns 60.35 ns 🟢 -4.33%
RWLock_rate_100/ (B/op) 2.00 B 2.00 B ⚪ 0%
RWLock_rate_100/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_1000/ (ns/op) 91.91 ns 86.78 ns 🟢 -5.58%
RWLock_rate_1000/ (B/op) 8.00 B 8.00 B ⚪ 0%
RWLock_rate_1000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkChange
Benchmark suite Previous Current Change
Push_10_Changes/ (ns/op) 4.54 ms 4.47 ms 🟢 -1.44%
Push_10_Changes/ (B/op) 150.42 KB 149.87 KB 🟢 -0.36%
Push_10_Changes/ (allocs/op) 1,623 allocs 1,623 allocs ⚪ 0%
Push_100_Changes/ (ns/op) 16.52 ms 16.39 ms 🟢 -0.75%
Push_100_Changes/ (B/op) 770.59 KB 781.79 KB 🔴 +1.45%
Push_100_Changes/ (allocs/op) 8,509 allocs 8,511 allocs 🔴 +0.02%
Push_1000_Changes/ (ns/op) 129.20 ms 131.25 ms 🔴 +1.58%
Push_1000_Changes/ (B/op) 7.22 MB 7.19 MB 🟢 -0.45%
Push_1000_Changes/ (allocs/op) 79,325 allocs 79,325 allocs ⚪ 0%
Pull_10_Changes/ (ns/op) 3.70 ms 3.65 ms 🟢 -1.31%
Pull_10_Changes/ (B/op) 124.59 KB 124.56 KB 🟢 -0.02%
Pull_10_Changes/ (allocs/op) 1,456 allocs 1,454 allocs 🟢 -0.14%
Pull_100_Changes/ (ns/op) 5.32 ms 5.26 ms 🟢 -1.24%
Pull_100_Changes/ (B/op) 354.61 KB 354.87 KB 🔴 +0.07%
Pull_100_Changes/ (allocs/op) 5,182 allocs 5,180 allocs 🟢 -0.04%
Pull_1000_Changes/ (ns/op) 10.88 ms 10.86 ms 🟢 -0.10%
Pull_1000_Changes/ (B/op) 2.20 MB 2.20 MB 🟢 -0.14%
Pull_1000_Changes/ (allocs/op) 44,681 allocs 44,682 allocs ⚪ 0%
BenchmarkSnapshot
Benchmark suite Previous Current Change
Push_3KB_snapshot/ (ns/op) 19.55 ms 18.84 ms 🟢 -3.64%
Push_3KB_snapshot/ (B/op) 905.58 KB 896.48 KB 🟢 -1.00%
Push_3KB_snapshot/ (allocs/op) 8,516 allocs 8,512 allocs 🟢 -0.05%
Push_30KB_snapshot/ (ns/op) 132.18 ms 132.80 ms 🔴 +0.47%
Push_30KB_snapshot/ (B/op) 8.24 MB 8.15 MB 🟢 -1.06%
Push_30KB_snapshot/ (allocs/op) 89,008 allocs 87,802 allocs 🟢 -1.35%
Pull_3KB_snapshot/ (ns/op) 7.80 ms 7.36 ms 🟢 -5.72%
Pull_3KB_snapshot/ (B/op) 1.12 MB 1.06 MB 🟢 -4.90%
Pull_3KB_snapshot/ (allocs/op) 20,064 allocs 19,254 allocs 🟢 -4.04%
Pull_30KB_snapshot/ (ns/op) 19.91 ms 19.01 ms 🟢 -4.51%
Pull_30KB_snapshot/ (B/op) 9.31 MB 8.77 MB 🟢 -5.86%
Pull_30KB_snapshot/ (allocs/op) 193,610 allocs 185,672 allocs 🟢 -4.10%
BenchmarkSplayTree
Benchmark suite Previous Current Change
stress_test_100000/ (ns/op) 0.19 ns 0.19 ns 🔴 +0.31%
stress_test_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_200000/ (ns/op) 0.40 ns 0.40 ns 🔴 +2.46%
stress_test_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_300000/ (ns/op) 0.57 ns 0.58 ns 🔴 +1.65%
stress_test_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_100000/ (ns/op) 0.01 ns 0.01 ns 🟢 -1.57%
random_access_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_200000/ (ns/op) 0.03 ns 0.04 ns 🔴 +12.35%
random_access_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_300000/ (ns/op) 0.04 ns 0.04 ns 🔴 +0.77%
random_access_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
editing_trace_bench/ (ns/op) 0.00 ns 0.00 ns 🔴 +8.68%
editing_trace_bench/ (B/op) 0.00 B 0.00 B ⚪ 0%
editing_trace_bench/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkSync
Benchmark suite Previous Current Change
memory_sync_10_test/ (ns/op) 7288.00 ns 7187.00 ns 🟢 -1.39%
memory_sync_10_test/ (B/op) 1.34 KB 1.34 KB 🔴 +0.07%
memory_sync_10_test/ (allocs/op) 35 allocs 35 allocs ⚪ 0%
memory_sync_100_test/ (ns/op) 55353.00 ns 55486.00 ns 🔴 +0.24%
memory_sync_100_test/ (B/op) 9.51 KB 9.50 KB 🟢 -0.02%
memory_sync_100_test/ (allocs/op) 268 allocs 268 allocs ⚪ 0%
memory_sync_1000_test/ (ns/op) 616285.00 ns 623115.00 ns 🔴 +1.11%
memory_sync_1000_test/ (B/op) 75.92 KB 75.72 KB 🟢 -0.26%
memory_sync_1000_test/ (allocs/op) 2,111 allocs 2,104 allocs 🟢 -0.33%
memory_sync_10000_test/ (ns/op) 7.47 ms 7.69 ms 🔴 +2.93%
memory_sync_10000_test/ (B/op) 761.49 KB 761.44 KB ⚪ 0%
memory_sync_10000_test/ (allocs/op) 20,475 allocs 20,489 allocs 🔴 +0.07%
BenchmarkTextEditing
Benchmark suite Previous Current Change
(ns/op) 5.18 s 5.19 s 🔴 +0.14%
(B/op) 3.92 GB 3.92 GB ⚪ 0%
(allocs/op) 20,619,777 allocs 20,619,754 allocs ⚪ 0%
BenchmarkTree
Benchmark suite Previous Current Change
10000_vertices_to_protobuf/ (ns/op) 4.17 ms 4.37 ms 🔴 +4.66%
10000_vertices_to_protobuf/ (B/op) 6.36 MB 6.36 MB ⚪ 0%
10000_vertices_to_protobuf/ (allocs/op) 70,025 allocs 70,025 allocs ⚪ 0%
10000_vertices_from_protobuf/ (ns/op) 217.30 ms 223.44 ms 🔴 +2.83%
10000_vertices_from_protobuf/ (B/op) 442.30 MB 442.31 MB ⚪ 0%
10000_vertices_from_protobuf/ (allocs/op) 290,038 allocs 290,039 allocs ⚪ 0%
20000_vertices_to_protobuf/ (ns/op) 8.84 ms 9.12 ms 🔴 +3.21%
20000_vertices_to_protobuf/ (B/op) 12.89 MB 12.89 MB ⚪ 0%
20000_vertices_to_protobuf/ (allocs/op) 140,028 allocs 140,028 allocs ⚪ 0%
20000_vertices_from_protobuf/ (ns/op) 884.61 ms 884.11 ms 🟢 -0.06%
20000_vertices_from_protobuf/ (B/op) 1.70 GB 1.70 GB ⚪ 0%
20000_vertices_from_protobuf/ (allocs/op) 580,043 allocs 580,044 allocs ⚪ 0%
30000_vertices_to_protobuf/ (ns/op) 14.26 ms 13.97 ms 🟢 -2.05%
30000_vertices_to_protobuf/ (B/op) 18.98 MB 18.98 MB ⚪ 0%
30000_vertices_to_protobuf/ (allocs/op) 210,029 allocs 210,029 allocs ⚪ 0%
30000_vertices_from_protobuf/ (ns/op) 2.00 s 2.00 s 🔴 +0.16%
30000_vertices_from_protobuf/ (B/op) 3.75 GB 3.75 GB ⚪ 0%
30000_vertices_from_protobuf/ (allocs/op) 870,147 allocs 870,143 allocs ⚪ 0%
BenchmarkVersionVector
Benchmark suite Previous Current Change
clients_10/ (ns/op) 160.21 ms 159.49 ms 🟢 -0.45%
clients_10/ (1_changepack(bytes)) 745.00 B 745.00 B ⚪ 0%
clients_10/ (2_snapshot(bytes)) 379.00 B 379.00 B ⚪ 0%
clients_10/ (3_pushpull(ms)) 8.00 ms 7.00 ms 🟢 -12.50%
clients_10/ (4_attach(ms)) 6.00 ms 6.00 ms ⚪ 0%
clients_10/ (5_changepack_after_detach(bytes)) 805.00 B 805.00 B ⚪ 0%
clients_10/ (6_snapshot_after_detach(bytes)) 136.00 B 136.00 B ⚪ 0%
clients_10/ (7_pushpull_after_detach(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (B/op) 19.93 MB 21.06 MB 🔴 +5.64%
clients_10/ (allocs/op) 83,762 allocs 83,263 allocs 🟢 -0.60%
clients_100/ (ns/op) 1.41 s 1.39 s 🟢 -1.31%
clients_100/ (1_changepack(bytes)) 6.14 KB 6.14 KB ⚪ 0%
clients_100/ (2_snapshot(bytes)) 3.08 KB 3.08 KB ⚪ 0%
clients_100/ (3_pushpull(ms)) 11.00 ms 11.00 ms ⚪ 0%
clients_100/ (4_attach(ms)) 11.00 ms 10.00 ms 🟢 -9.09%
clients_100/ (5_changepack_after_detach(bytes)) 6.21 KB 6.21 KB ⚪ 0%
clients_100/ (6_snapshot_after_detach(bytes)) 137.00 B 137.00 B ⚪ 0%
clients_100/ (7_pushpull_after_detach(ms)) 9.00 ms 9.00 ms ⚪ 0%
clients_100/ (B/op) 230.31 MB 215.11 MB 🟢 -6.60%
clients_100/ (allocs/op) 1,539,768 allocs 1,481,226 allocs 🟢 -3.80%
clients_1000/ (ns/op) 60.97 s 45.71 s 🟢 -25.03%
clients_1000/ (1_changepack(bytes)) 60.16 KB 60.16 KB ⚪ 0%
clients_1000/ (2_snapshot(bytes)) 30.08 KB 30.08 KB ⚪ 0%
clients_1000/ (3_pushpull(ms)) 95.00 ms 93.00 ms 🟢 -2.11%
clients_1000/ (4_attach(ms)) 249.00 ms 100.00 ms 🟢 -59.84%
clients_1000/ (5_changepack_after_detach(bytes)) 60.22 KB 60.22 KB ⚪ 0%
clients_1000/ (6_snapshot_after_detach(bytes)) 139.00 B 139.00 B ⚪ 0%
clients_1000/ (7_pushpull_after_detach(ms)) 26.00 ms 22.00 ms 🟢 -15.38%
clients_1000/ (B/op) 22.07 GB 6.43 GB 🟢 -70.85%
clients_1000/ (allocs/op) 111,762,106 allocs 93,353,871 allocs 🟢 -16.47%

Copy link

@hackerwins-yorkie hackerwins-yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark Analysis 📊

This is a comparison result between the previous(e687d61) and the current commit(b5429d7).

Significant Changes (≥20% difference)

Benchmark suite Previous Current Change
BenchmarkVersionVector/clients_1000/ (B/op) 22.07 GB 6.43 GB 🟢 -70.85%
BenchmarkVersionVector/clients_1000/ (4_attach(ms)) 249.00 ms 99.00 ms 🟢 -60.24%
BenchmarkVersionVector/clients_1000/ (ns/op) 60.97 s 46.94 s 🟢 -23.01%

Key Observations 🔍

  • The BenchmarkVersionVector suite exhibited significant improvements in performance with a decrease of 70.85% in memory consumption (B/op) for the clients_1000 test. This substantial optimization could lead to enhanced efficiency and resource utilization in scenarios involving a high number of clients.
  • In the BenchmarkTree suite, the 10000_vertices_from_protobuf test showed an increase of 4.31% in processing time (ns/op). Similarly, the 20000_vertices_to_protobuf test experienced a 3.41% increase in processing time. These increments suggest potential areas for further optimization to streamline vertex data handling in the tree structure.
  • Across various benchmark suites, the trend of minor performance improvements is noticeable, with several tests displaying marginal decreases in processing times (ns/op) and memory usage (B/op). These incremental enhancements indicate ongoing efforts to refine the efficiency and effectiveness of the tested functionalities.

Clock Analysis

Lamport (v0.5.2)

Metric 10 clients 100 clients 1000 clients
Total Operation Time 84.96 ms 793.94 ms 34.79 s
Memory Allocations 35.11 MB 219.92 MB 4.91 GB
Number of Allocations (allocs/op) 69,271 1,246,728 81,485,288
ChangePack Size 138.0 B 137.0 B 141.0 B
Snapshot Size 379.0 B 3.08 KB 30.08 KB
Push-Pull Time 2.0 ms 1.5 ms 4.0 ms
Attach Time 4.5 ms 11.0 ms 31.0 ms
ChangePack After Detach 138.0 B 140.0 B 141.0 B
Snapshot After Detach 136.0 B 137.0 B 139.0 B
Push-Pull After Detach 2.5 ms 5.0 ms 9.5 ms

VV (current)

Metric 10 clients 100 clients 1000 clients
Total Operation Time (ns/op) 161.52 ms 1.43 s 46.94 s
Memory Allocated (B/op) 20.73 MB 215.94 MB 6.43 GB
Number of Allocations (allocs/op) 83,261 1,481,218 93,356,999
ChangePack Size (bytes) 745.00 B 6.14 KB 60.16 KB
Snapshot Size (bytes) 379.00 B 3.08 KB 30.08 KB
Push-Pull Time (ms) 8.00 ms 11.00 ms 94.00 ms
Attach Time (ms) 6.00 ms 9.00 ms 99.00 ms
ChangePack After Detach (bytes) 805.00 B 6.21 KB 60.22 KB
Snapshot After Detach (bytes) 136.00 B 137.00 B 139.00 B
Push-Pull After Detach (ms) 8.00 ms 10.00 ms 23.00 ms

Summary

  • Lamport clock shows better performance in total operation time for 10 clients, but Version Vector performs better for 100 and 1000 clients.
  • Memory allocations are higher for Version Vector across all client scenarios.
  • The number of allocations is significantly higher for Version Vector compared to Lamport clock.
  • Version Vector has larger ChangePack and Snapshot sizes but lower Push-Pull times compared to Lamport clock.
  • The Attach time for Version Vector is more consistent and lower than Lamport clock across all client scenarios.
  • ChangePack and Snapshot sizes after detach are larger for Version Vector.
  • Push-Pull time after detach is better for Version Vector in 10 and 100 client scenarios, but worse for 1000 clients.

Detailed Test Results

BenchmarkDocument
Benchmark suite Previous Current Change
constructor_test/ (ns/op) 1439.00 ns 1459.00 ns 🔴 +1.39%
constructor_test/ (B/op) 1.39 KB 1.43 KB 🔴 +3.47%
constructor_test/ (allocs/op) 24 allocs 25 allocs 🔴 +4.17%
status_test/ (ns/op) 1028.00 ns 1067.00 ns 🔴 +3.79%
status_test/ (B/op) 1.35 KB 1.40 KB 🔴 +3.55%
status_test/ (allocs/op) 22 allocs 23 allocs 🔴 +4.55%
equals_test/ (ns/op) 7864.00 ns 8148.00 ns 🔴 +3.61%
equals_test/ (B/op) 7.56 KB 7.71 KB 🔴 +1.90%
equals_test/ (allocs/op) 129 allocs 132 allocs 🔴 +2.33%
nested_update_test/ (ns/op) 17079.00 ns 17062.00 ns 🟢 -0.10%
nested_update_test/ (B/op) 12.31 KB 12.36 KB 🔴 +0.39%
nested_update_test/ (allocs/op) 258 allocs 259 allocs 🔴 +0.39%
delete_test/ (ns/op) 27313.00 ns 22845.00 ns 🟢 -16.36%
delete_test/ (B/op) 15.79 KB 15.84 KB 🔴 +0.30%
delete_test/ (allocs/op) 339 allocs 340 allocs 🔴 +0.29%
object_test/ (ns/op) 8546.00 ns 8573.00 ns 🔴 +0.32%
object_test/ (B/op) 7.03 KB 7.08 KB 🔴 +0.68%
object_test/ (allocs/op) 118 allocs 119 allocs 🔴 +0.85%
array_test/ (ns/op) 28984.00 ns 28384.00 ns 🟢 -2.07%
array_test/ (B/op) 12.14 KB 12.19 KB 🔴 +0.40%
array_test/ (allocs/op) 273 allocs 274 allocs 🔴 +0.37%
text_test/ (ns/op) 32155.00 ns 38483.00 ns 🔴 +19.68%
text_test/ (B/op) 15.19 KB 15.24 KB 🔴 +0.32%
text_test/ (allocs/op) 484 allocs 485 allocs 🔴 +0.21%
text_composition_test/ (ns/op) 31674.00 ns 31714.00 ns 🔴 +0.13%
text_composition_test/ (B/op) 18.70 KB 18.75 KB 🔴 +0.26%
text_composition_test/ (allocs/op) 501 allocs 502 allocs 🔴 +0.20%
rich_text_test/ (ns/op) 87424.00 ns 85966.00 ns 🟢 -1.67%
rich_text_test/ (B/op) 39.36 KB 39.40 KB 🔴 +0.12%
rich_text_test/ (allocs/op) 1,146 allocs 1,147 allocs 🔴 +0.09%
counter_test/ (ns/op) 18201.00 ns 18280.00 ns 🔴 +0.43%
counter_test/ (B/op) 11.81 KB 11.86 KB 🔴 +0.41%
counter_test/ (allocs/op) 253 allocs 254 allocs 🔴 +0.40%
text_edit_gc_100/ (ns/op) 1.39 ms 1.42 ms 🔴 +2.35%
text_edit_gc_100/ (B/op) 864.90 KB 864.92 KB ⚪ 0%
text_edit_gc_100/ (allocs/op) 17,281 allocs 17,283 allocs 🔴 +0.01%
text_edit_gc_1000/ (ns/op) 53.39 ms 53.66 ms 🔴 +0.51%
text_edit_gc_1000/ (B/op) 46.84 MB 46.84 MB ⚪ 0%
text_edit_gc_1000/ (allocs/op) 185,598 allocs 185,595 allocs ⚪ 0%
text_split_gc_100/ (ns/op) 2.12 ms 2.12 ms 🟢 -0.07%
text_split_gc_100/ (B/op) 1.58 MB 1.58 MB ⚪ 0%
text_split_gc_100/ (allocs/op) 15,950 allocs 15,951 allocs ⚪ 0%
text_split_gc_1000/ (ns/op) 128.25 ms 129.43 ms 🔴 +0.92%
text_split_gc_1000/ (B/op) 137.79 MB 137.79 MB ⚪ 0%
text_split_gc_1000/ (allocs/op) 185,000 allocs 185,000 allocs ⚪ 0%
text_delete_all_10000/ (ns/op) 18.43 ms 17.78 ms 🟢 -3.55%
text_delete_all_10000/ (B/op) 10.58 MB 10.58 MB ⚪ 0%
text_delete_all_10000/ (allocs/op) 56,134 allocs 56,136 allocs ⚪ 0%
text_delete_all_100000/ (ns/op) 312.31 ms 288.54 ms 🟢 -7.61%
text_delete_all_100000/ (B/op) 105.54 MB 105.51 MB 🟢 -0.03%
text_delete_all_100000/ (allocs/op) 566,133 allocs 566,034 allocs 🟢 -0.02%
text_100/ (ns/op) 234634.00 ns 232723.00 ns 🟢 -0.81%
text_100/ (B/op) 120.94 KB 120.99 KB 🔴 +0.04%
text_100/ (allocs/op) 5,181 allocs 5,182 allocs 🔴 +0.02%
text_1000/ (ns/op) 2.46 ms 2.47 ms 🔴 +0.34%
text_1000/ (B/op) 1.16 MB 1.16 MB ⚪ 0%
text_1000/ (allocs/op) 51,084 allocs 51,085 allocs ⚪ 0%
array_1000/ (ns/op) 1.24 ms 1.25 ms 🔴 +0.45%
array_1000/ (B/op) 1.09 MB 1.09 MB 🔴 +0.01%
array_1000/ (allocs/op) 11,879 allocs 11,880 allocs ⚪ 0%
array_10000/ (ns/op) 13.33 ms 13.30 ms 🟢 -0.24%
array_10000/ (B/op) 9.89 MB 9.89 MB ⚪ 0%
array_10000/ (allocs/op) 120,735 allocs 120,732 allocs ⚪ 0%
array_gc_100/ (ns/op) 131750.00 ns 132529.00 ns 🔴 +0.59%
array_gc_100/ (B/op) 99.89 KB 99.95 KB 🔴 +0.05%
array_gc_100/ (allocs/op) 1,266 allocs 1,267 allocs 🔴 +0.08%
array_gc_1000/ (ns/op) 1.42 ms 1.42 ms 🟢 -0.29%
array_gc_1000/ (B/op) 1.14 MB 1.14 MB 🔴 +0.01%
array_gc_1000/ (allocs/op) 12,926 allocs 12,928 allocs 🔴 +0.02%
counter_1000/ (ns/op) 202098.00 ns 199985.00 ns 🟢 -1.05%
counter_1000/ (B/op) 178.13 KB 178.18 KB 🔴 +0.03%
counter_1000/ (allocs/op) 5,771 allocs 5,772 allocs 🔴 +0.02%
counter_10000/ (ns/op) 2.17 ms 2.15 ms 🟢 -0.82%
counter_10000/ (B/op) 2.07 MB 2.07 MB ⚪ 0%
counter_10000/ (allocs/op) 59,778 allocs 59,779 allocs ⚪ 0%
object_1000/ (ns/op) 1.39 ms 1.40 ms 🔴 +0.70%
object_1000/ (B/op) 1.44 MB 1.44 MB 🔴 +0.03%
object_1000/ (allocs/op) 9,925 allocs 9,926 allocs 🔴 +0.01%
object_10000/ (ns/op) 14.82 ms 14.97 ms 🔴 +1.06%
object_10000/ (B/op) 12.35 MB 12.35 MB 🔴 +0.02%
object_10000/ (allocs/op) 101,232 allocs 101,246 allocs 🔴 +0.01%
tree_100/ (ns/op) 1.02 ms 1.02 ms 🟢 -0.22%
tree_100/ (B/op) 951.02 KB 951.07 KB ⚪ 0%
tree_100/ (allocs/op) 6,102 allocs 6,103 allocs 🔴 +0.02%
tree_1000/ (ns/op) 74.23 ms 75.49 ms 🔴 +1.69%
tree_1000/ (B/op) 86.58 MB 86.58 MB ⚪ 0%
tree_1000/ (allocs/op) 60,111 allocs 60,113 allocs ⚪ 0%
tree_10000/ (ns/op) 9.68 s 9.68 s 🟢 -0.03%
tree_10000/ (B/op) 8.58 GB 8.58 GB ⚪ 0%
tree_10000/ (allocs/op) 600,173 allocs 600,190 allocs ⚪ 0%
tree_delete_all_1000/ (ns/op) 78.41 ms 76.98 ms 🟢 -1.82%
tree_delete_all_1000/ (B/op) 87.57 MB 87.57 MB ⚪ 0%
tree_delete_all_1000/ (allocs/op) 75,289 allocs 75,291 allocs ⚪ 0%
tree_edit_gc_100/ (ns/op) 3.96 ms 3.83 ms 🟢 -3.25%
tree_edit_gc_100/ (B/op) 4.15 MB 4.15 MB ⚪ 0%
tree_edit_gc_100/ (allocs/op) 15,147 allocs 15,147 allocs ⚪ 0%
tree_edit_gc_1000/ (ns/op) 332.75 ms 315.76 ms 🟢 -5.10%
tree_edit_gc_1000/ (B/op) 384.04 MB 384.05 MB ⚪ 0%
tree_edit_gc_1000/ (allocs/op) 154,952 allocs 154,950 allocs ⚪ 0%
tree_split_gc_100/ (ns/op) 2.67 ms 2.62 ms 🟢 -1.99%
tree_split_gc_100/ (B/op) 2.41 MB 2.41 MB ⚪ 0%
tree_split_gc_100/ (allocs/op) 11,131 allocs 11,132 allocs ⚪ 0%
tree_split_gc_1000/ (ns/op) 197.74 ms 193.35 ms 🟢 -2.22%
tree_split_gc_1000/ (B/op) 222.50 MB 222.50 MB ⚪ 0%
tree_split_gc_1000/ (allocs/op) 122,053 allocs 122,064 allocs ⚪ 0%
BenchmarkRPC
Benchmark suite Previous Current Change
client_to_server/ (ns/op) 431.85 ms 421.09 ms 🟢 -2.49%
client_to_server/ (B/op) 16.13 MB 16.10 MB 🟢 -0.17%
client_to_server/ (allocs/op) 223,674 allocs 223,158 allocs 🟢 -0.23%
client_to_client_via_server/ (ns/op) 788.62 ms 785.19 ms 🟢 -0.43%
client_to_client_via_server/ (B/op) 37.20 MB 35.30 MB 🟢 -5.11%
client_to_client_via_server/ (allocs/op) 478,656 allocs 474,350 allocs 🟢 -0.90%
attach_large_document/ (ns/op) 1.32 s 1.33 s 🔴 +0.75%
attach_large_document/ (B/op) 1.89 GB 1.92 GB 🔴 +1.72%
attach_large_document/ (allocs/op) 12,321 allocs 12,332 allocs 🔴 +0.09%
adminCli_to_server/ (ns/op) 542.08 ms 545.63 ms 🔴 +0.65%
adminCli_to_server/ (B/op) 21.76 MB 21.53 MB 🟢 -1.03%
adminCli_to_server/ (allocs/op) 291,952 allocs 316,683 allocs 🔴 +8.47%
BenchmarkLocker
Benchmark suite Previous Current Change
(ns/op) 82.86 ns 80.82 ns 🟢 -2.46%
(B/op) 32.00 B 32.00 B ⚪ 0%
(allocs/op) 1 allocs 1 allocs ⚪ 0%
BenchmarkLockerParallel
Benchmark suite Previous Current Change
(ns/op) 45.80 ns 44.95 ns 🟢 -1.86%
(B/op) 0.00 B 0.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkLockerMoreKeys
Benchmark suite Previous Current Change
(ns/op) 180.50 ns 176.00 ns 🟢 -2.49%
(B/op) 31.00 B 31.00 B ⚪ 0%
(allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkRWLocker
Benchmark suite Previous Current Change
RWLock_rate_2/ (ns/op) 50.25 ns 49.22 ns 🟢 -2.05%
RWLock_rate_2/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_2/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_10/ (ns/op) 44.88 ns 43.21 ns 🟢 -3.72%
RWLock_rate_10/ (B/op) 0.00 B 0.00 B ⚪ 0%
RWLock_rate_10/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_100/ (ns/op) 63.08 ns 58.47 ns 🟢 -7.31%
RWLock_rate_100/ (B/op) 2.00 B 2.00 B ⚪ 0%
RWLock_rate_100/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
RWLock_rate_1000/ (ns/op) 91.91 ns 87.34 ns 🟢 -4.97%
RWLock_rate_1000/ (B/op) 8.00 B 8.00 B ⚪ 0%
RWLock_rate_1000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkChange
Benchmark suite Previous Current Change
Push_10_Changes/ (ns/op) 4.54 ms 4.52 ms 🟢 -0.50%
Push_10_Changes/ (B/op) 150.42 KB 150.37 KB 🟢 -0.03%
Push_10_Changes/ (allocs/op) 1,623 allocs 1,623 allocs ⚪ 0%
Push_100_Changes/ (ns/op) 16.52 ms 16.76 ms 🔴 +1.48%
Push_100_Changes/ (B/op) 770.59 KB 779.07 KB 🔴 +1.10%
Push_100_Changes/ (allocs/op) 8,509 allocs 8,511 allocs 🔴 +0.02%
Push_1000_Changes/ (ns/op) 129.20 ms 132.25 ms 🔴 +2.36%
Push_1000_Changes/ (B/op) 7.22 MB 7.03 MB 🟢 -2.59%
Push_1000_Changes/ (allocs/op) 79,325 allocs 79,321 allocs ⚪ 0%
Pull_10_Changes/ (ns/op) 3.70 ms 3.72 ms 🔴 +0.48%
Pull_10_Changes/ (B/op) 124.59 KB 124.43 KB 🟢 -0.12%
Pull_10_Changes/ (allocs/op) 1,456 allocs 1,454 allocs 🟢 -0.14%
Pull_100_Changes/ (ns/op) 5.32 ms 5.35 ms 🔴 +0.44%
Pull_100_Changes/ (B/op) 354.61 KB 354.26 KB 🟢 -0.10%
Pull_100_Changes/ (allocs/op) 5,182 allocs 5,180 allocs 🟢 -0.04%
Pull_1000_Changes/ (ns/op) 10.88 ms 11.19 ms 🔴 +2.86%
Pull_1000_Changes/ (B/op) 2.20 MB 2.20 MB 🟢 -0.18%
Pull_1000_Changes/ (allocs/op) 44,681 allocs 44,680 allocs ⚪ 0%
BenchmarkSnapshot
Benchmark suite Previous Current Change
Push_3KB_snapshot/ (ns/op) 19.55 ms 19.03 ms 🟢 -2.67%
Push_3KB_snapshot/ (B/op) 905.58 KB 901.77 KB 🟢 -0.42%
Push_3KB_snapshot/ (allocs/op) 8,516 allocs 8,513 allocs 🟢 -0.04%
Push_30KB_snapshot/ (ns/op) 132.18 ms 135.55 ms 🔴 +2.55%
Push_30KB_snapshot/ (B/op) 8.24 MB 8.14 MB 🟢 -1.22%
Push_30KB_snapshot/ (allocs/op) 89,008 allocs 88,281 allocs 🟢 -0.82%
Pull_3KB_snapshot/ (ns/op) 7.80 ms 7.50 ms 🟢 -3.96%
Pull_3KB_snapshot/ (B/op) 1.12 MB 1.06 MB 🟢 -5.01%
Pull_3KB_snapshot/ (allocs/op) 20,064 allocs 19,253 allocs 🟢 -4.04%
Pull_30KB_snapshot/ (ns/op) 19.91 ms 19.64 ms 🟢 -1.37%
Pull_30KB_snapshot/ (B/op) 9.31 MB 8.76 MB 🟢 -5.94%
Pull_30KB_snapshot/ (allocs/op) 193,610 allocs 185,674 allocs 🟢 -4.10%
BenchmarkSplayTree
Benchmark suite Previous Current Change
stress_test_100000/ (ns/op) 0.19 ns 0.19 ns 🟢 -1.70%
stress_test_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_200000/ (ns/op) 0.40 ns 0.39 ns 🟢 -0.94%
stress_test_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
stress_test_300000/ (ns/op) 0.57 ns 0.56 ns 🟢 -0.91%
stress_test_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
stress_test_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_100000/ (ns/op) 0.01 ns 0.01 ns 🟢 -1.34%
random_access_100000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_100000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_200000/ (ns/op) 0.03 ns 0.03 ns 🟢 -2.04%
random_access_200000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_200000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
random_access_300000/ (ns/op) 0.04 ns 0.05 ns 🔴 +5.88%
random_access_300000/ (B/op) 0.00 B 0.00 B ⚪ 0%
random_access_300000/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
editing_trace_bench/ (ns/op) 0.00 ns 0.00 ns 🔴 +10.01%
editing_trace_bench/ (B/op) 0.00 B 0.00 B ⚪ 0%
editing_trace_bench/ (allocs/op) 0 allocs 0 allocs ⚪ 0%
BenchmarkSync
Benchmark suite Previous Current Change
memory_sync_10_test/ (ns/op) 7288.00 ns 7258.00 ns 🟢 -0.41%
memory_sync_10_test/ (B/op) 1.34 KB 1.34 KB ⚪ 0%
memory_sync_10_test/ (allocs/op) 35 allocs 35 allocs ⚪ 0%
memory_sync_100_test/ (ns/op) 55353.00 ns 55916.00 ns 🔴 +1.02%
memory_sync_100_test/ (B/op) 9.51 KB 9.52 KB 🔴 +0.19%
memory_sync_100_test/ (allocs/op) 268 allocs 268 allocs ⚪ 0%
memory_sync_1000_test/ (ns/op) 616285.00 ns 614126.00 ns 🟢 -0.35%
memory_sync_1000_test/ (B/op) 75.92 KB 76.38 KB 🔴 +0.60%
memory_sync_1000_test/ (allocs/op) 2,111 allocs 2,125 allocs 🔴 +0.66%
memory_sync_10000_test/ (ns/op) 7.47 ms 8.05 ms 🔴 +7.74%
memory_sync_10000_test/ (B/op) 761.49 KB 761.00 KB 🟢 -0.06%
memory_sync_10000_test/ (allocs/op) 20,475 allocs 20,476 allocs ⚪ 0%
BenchmarkTextEditing
Benchmark suite Previous Current Change
(ns/op) 5.18 s 5.29 s 🔴 +2.21%
(B/op) 3.92 GB 3.92 GB ⚪ 0%
(allocs/op) 20,619,777 allocs 20,619,841 allocs ⚪ 0%
BenchmarkTree
Benchmark suite Previous Current Change
10000_vertices_to_protobuf/ (ns/op) 4.17 ms 4.34 ms 🔴 +4.01%
10000_vertices_to_protobuf/ (B/op) 6.36 MB 6.36 MB ⚪ 0%
10000_vertices_to_protobuf/ (allocs/op) 70,025 allocs 70,025 allocs ⚪ 0%
10000_vertices_from_protobuf/ (ns/op) 217.30 ms 226.66 ms 🔴 +4.31%
10000_vertices_from_protobuf/ (B/op) 442.30 MB 442.31 MB ⚪ 0%
10000_vertices_from_protobuf/ (allocs/op) 290,038 allocs 290,039 allocs ⚪ 0%
20000_vertices_to_protobuf/ (ns/op) 8.84 ms 9.14 ms 🔴 +3.41%
20000_vertices_to_protobuf/ (B/op) 12.89 MB 12.89 MB ⚪ 0%
20000_vertices_to_protobuf/ (allocs/op) 140,028 allocs 140,028 allocs ⚪ 0%
20000_vertices_from_protobuf/ (ns/op) 884.61 ms 900.39 ms 🔴 +1.78%
20000_vertices_from_protobuf/ (B/op) 1.70 GB 1.70 GB ⚪ 0%
20000_vertices_from_protobuf/ (allocs/op) 580,043 allocs 580,046 allocs ⚪ 0%
30000_vertices_to_protobuf/ (ns/op) 14.26 ms 14.09 ms 🟢 -1.19%
30000_vertices_to_protobuf/ (B/op) 18.98 MB 18.98 MB ⚪ 0%
30000_vertices_to_protobuf/ (allocs/op) 210,029 allocs 210,029 allocs ⚪ 0%
30000_vertices_from_protobuf/ (ns/op) 2.00 s 1.99 s 🟢 -0.63%
30000_vertices_from_protobuf/ (B/op) 3.75 GB 3.75 GB ⚪ 0%
30000_vertices_from_protobuf/ (allocs/op) 870,147 allocs 870,149 allocs ⚪ 0%
BenchmarkVersionVector
Benchmark suite Previous Current Change
clients_10/ (ns/op) 160.21 ms 161.52 ms 🔴 +0.82%
clients_10/ (1_changepack(bytes)) 745.00 B 745.00 B ⚪ 0%
clients_10/ (2_snapshot(bytes)) 379.00 B 379.00 B ⚪ 0%
clients_10/ (3_pushpull(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (4_attach(ms)) 6.00 ms 6.00 ms ⚪ 0%
clients_10/ (5_changepack_after_detach(bytes)) 805.00 B 805.00 B ⚪ 0%
clients_10/ (6_snapshot_after_detach(bytes)) 136.00 B 136.00 B ⚪ 0%
clients_10/ (7_pushpull_after_detach(ms)) 8.00 ms 8.00 ms ⚪ 0%
clients_10/ (B/op) 19.93 MB 20.73 MB 🔴 +3.99%
clients_10/ (allocs/op) 83,762 allocs 83,261 allocs 🟢 -0.60%
clients_100/ (ns/op) 1.41 s 1.43 s 🔴 +1.57%
clients_100/ (1_changepack(bytes)) 6.14 KB 6.14 KB ⚪ 0%
clients_100/ (2_snapshot(bytes)) 3.08 KB 3.08 KB ⚪ 0%
clients_100/ (3_pushpull(ms)) 11.00 ms 11.00 ms ⚪ 0%
clients_100/ (4_attach(ms)) 11.00 ms 9.00 ms 🟢 -18.18%
clients_100/ (5_changepack_after_detach(bytes)) 6.21 KB 6.21 KB ⚪ 0%
clients_100/ (6_snapshot_after_detach(bytes)) 137.00 B 137.00 B ⚪ 0%
clients_100/ (7_pushpull_after_detach(ms)) 9.00 ms 10.00 ms 🔴 +11.11%
clients_100/ (B/op) 230.31 MB 215.94 MB 🟢 -6.24%
clients_100/ (allocs/op) 1,539,768 allocs 1,481,218 allocs 🟢 -3.80%
clients_1000/ (ns/op) 60.97 s 46.94 s 🟢 -23.01%
clients_1000/ (1_changepack(bytes)) 60.16 KB 60.16 KB ⚪ 0%
clients_1000/ (2_snapshot(bytes)) 30.08 KB 30.08 KB ⚪ 0%
clients_1000/ (3_pushpull(ms)) 95.00 ms 94.00 ms 🟢 -1.05%
clients_1000/ (4_attach(ms)) 249.00 ms 99.00 ms 🟢 -60.24%
clients_1000/ (5_changepack_after_detach(bytes)) 60.22 KB 60.22 KB ⚪ 0%
clients_1000/ (6_snapshot_after_detach(bytes)) 139.00 B 139.00 B ⚪ 0%
clients_1000/ (7_pushpull_after_detach(ms)) 26.00 ms 23.00 ms 🟢 -11.54%
clients_1000/ (B/op) 22.07 GB 6.43 GB 🟢 -70.85%
clients_1000/ (allocs/op) 111,762,106 allocs 93,356,999 allocs 🟢 -16.47%

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the loop to use direct indexing instead of range to avoid potential pointer aliasing issues. Using range in this context could lead to unintended shared references to memory, while direct indexing ensures each element is safely referenced. This change improves the safety and stability of the code.

For more context, refer to this StackOverflow discussion on implicit memory aliasing in for loops: https://stackoverflow.com/questions/62446118/implicit-memory-aliasing-in-for-loop

@chacha912 chacha912 self-requested a review February 21, 2025 07:37
Copy link
Contributor

@chacha912 chacha912 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the review comments!
Since Min function is now modified in-place as well, we could refactor the previously added database.FindMinVersionVector(#1153) in a future task.

@chacha912 chacha912 merged commit 2fd75be into main Feb 25, 2025
5 checks passed
@chacha912 chacha912 deleted the in-place-vv branch February 25, 2025 03:50
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.

Performance Optimization for minVV and maxVV calculation
4 participants