Skip to content

add BenchmarkReceive10kRowsCompress #1704

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

Merged
merged 2 commits into from
Apr 23, 2025

Conversation

methane
Copy link
Member

@methane methane commented Apr 23, 2025

Description

  • Rename BenchmarkReceiveMassiveRows to BenchmarkReceive10kRows
  • Add BenchmarkReceive10kRowsCompress that run BenchmarkReceiveMassiveRows with compression
  • Other tiny benchmark improvements.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Summary by CodeRabbit

  • Tests
    • Improved and expanded Go benchmark tests for database operations, including new benchmarks for compressed and uncompressed scenarios.
    • Enhanced efficiency and clarity of benchmark setup and execution.
    • Updated naming conventions for benchmark functions for better consistency.
  • Chores
    • Added an automated benchmark step to the continuous integration workflow.

Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

The changes introduce a new benchmark step in the GitHub Actions workflow to run Go benchmarks as part of the CI process. In the Go benchmark test file, several functions are renamed for clarity and consistency, and benchmarking practices are updated to use b.ReportAllocs() and b.ResetTimer() after setup instead of stopping the timer before setup. The handling of large-row benchmarks is refactored for efficiency and clarity, with new benchmarks added for compressed and uncompressed scenarios, and setup code optimized to reduce repeated allocations.

Changes

File(s) Change Summary
.github/workflows/test.yml Added a new "benchmark" step to the "test" job, running Go benchmarks using go test -run '^$' -bench . immediately after the test step and before coverage upload.
benchmark_test.go Renamed several benchmark functions and parameters for clarity (e.g., useCompressioncompress, BenchmarkQueryCompressionBenchmarkQueryCompressed). Updated benchmark setup to use b.ReportAllocs() and b.ResetTimer() after setup instead of b.StopTimer() before setup. Refactored large-row benchmark: split into helper (benchmark10kRows) and two exported benchmarks for compressed/uncompressed cases. Optimized setup for inserting 10,000 rows by pre-filling argument slices, and moved scan variable declarations outside loops to reduce allocations. Improved error handling and added comments for clarity and Go version compatibility.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Go Test Runner

    GitHub Actions->>Go Test Runner: Run tests (go test)
    GitHub Actions->>Go Test Runner: Run benchmarks (go test -run '^$' -bench .)
    GitHub Actions->>Go Test Runner: Upload coverage
Loading

Poem

In the warren, benchmarks run anew,
With timers reset and allocations in view.
Compression or not, ten thousand rows fly,
As rabbits refactor and code hops high.
CI now tests with a bounding leap—
Fast and efficient, our carrots we reap!
🐇✨


📜 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 89859a2 and 3cb6049.

📒 Files selected for processing (2)
  • .github/workflows/test.yml (1 hunks)
  • benchmark_test.go (10 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/test.yml
  • benchmark_test.go
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: test (ubuntu-latest, 1.22, 9.0)
  • GitHub Check: test (macos-latest, 1.24, mariadb-10.5)
  • GitHub Check: test (windows-latest, 1.24, mariadb-10.11)
  • GitHub Check: test (windows-latest, 1.24, mariadb-10.5)
  • GitHub Check: test (windows-latest, 1.24, 5.7)
  • GitHub Check: test (windows-latest, 1.24, mariadb-10.6)
  • GitHub Check: test (windows-latest, 1.24, mariadb-11.2)
  • GitHub Check: test (windows-latest, 1.24, mariadb-11.1)
  • GitHub Check: test (windows-latest, 1.24, 8.0)
  • GitHub Check: test (macos-latest, 1.24, mariadb-10.6)
  • GitHub Check: test (windows-latest, 1.24, 8.4)
  • GitHub Check: test (windows-latest, 1.24, mariadb-11.4)
  • GitHub Check: test (windows-latest, 1.24, 9.0)
  • GitHub Check: test (macos-latest, 1.24, 8.4)
  • GitHub Check: test (macos-latest, 1.24, 8.0)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-10.6)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-10.5)
  • GitHub Check: test (ubuntu-latest, 1.24, 5.7)
  • GitHub Check: test (ubuntu-latest, 1.24, 8.0)
  • GitHub Check: test (ubuntu-latest, 1.24, 9.0)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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

@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 (2)
benchmark_test.go (2)

74-74: Consider using consistent parameter naming.

The parameter name compr here differs from the compress used in initDB. For consistency across the codebase, consider using the same parameter name in both functions.

-func benchmarkQuery(b *testing.B, compr bool) {
+func benchmarkQuery(b *testing.B, compress bool) {

388-448: Great refactoring of the row benchmark with several optimizations.

The refactoring of BenchmarkReceiveMassiveRows into a helper benchmark10kRows function with several optimizations:

  1. Pre-filling the repeated string values in the args slice once (lines 402-405)
  2. Moving variable declarations outside the loop to reduce allocations (lines 433-434)
  3. Proper resource cleanup with rows.Close() in all cases
  4. Using b.Run() to avoid repeating heavy setup

There's a minor typo in the comment on line 421: "fot this purpose" should be "for this purpose".

-	// Go 1.24 introduced b.Loop() fot this purpose. But we keep this
+	// Go 1.24 introduced b.Loop() for this purpose. But we keep this
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7da50ff and 89859a2.

📒 Files selected for processing (2)
  • .github/workflows/test.yml (1 hunks)
  • benchmark_test.go (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: test (ubuntu-latest, 1.23, 9.0)
  • GitHub Check: test (windows-latest, 1.24, mariadb-11.2)
  • GitHub Check: test (windows-latest, 1.24, mariadb-10.6)
  • GitHub Check: test (windows-latest, 1.24, 8.4)
  • GitHub Check: test (macos-latest, 1.24, 8.4)
  • GitHub Check: test (windows-latest, 1.24, 8.0)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-10.6)
  • GitHub Check: test (macos-latest, 1.24, mariadb-11.4)
  • GitHub Check: test (macos-latest, 1.24, 5.7)
  • GitHub Check: test (macos-latest, 1.24, mariadb-11.2)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-10.11)
  • GitHub Check: test (macos-latest, 1.24, 9.0)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-11.4)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-11.1)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-10.5)
  • GitHub Check: test (ubuntu-latest, 1.24, mariadb-11.2)
  • GitHub Check: test (ubuntu-latest, 1.24, 8.0)
  • GitHub Check: test (ubuntu-latest, 1.24, 5.7)
🔇 Additional comments (7)
.github/workflows/test.yml (1)

99-102: Good addition of benchmark step to CI pipeline.

Adding a dedicated benchmark step ensures benchmark performance is tracked as part of continuous integration. The placement after tests but before coverage upload is appropriate, and using -run '^$' to skip regular tests is the correct approach.

benchmark_test.go (6)

49-49: LGTM! Parameter name simplification.

The parameter rename from useCompression to compress makes the code more concise while maintaining clarity.


67-72: LGTM! Better function naming.

Renaming from BenchmarkQueryCompression to BenchmarkQueryCompressed and updating the helper function name to benchmarkQuery improves clarity and follows the pattern used by other benchmarks.


129-130: LGTM! Improved benchmark timing practices.

Using b.ReportAllocs() and b.ResetTimer() after setup instead of stopping the timer before setup follows better Go benchmarking practices. This approach consistently measures the actual operation while excluding setup time.


166-168: LGTM! Consistent benchmark timing practices.

The consistent use of b.ReportAllocs() and b.ResetTimer() across all benchmarks improves the accuracy and reliability of benchmark results.


202-203: LGTM! Consistent benchmark timing practices.

Maintaining consistent timing practices across all benchmarks.


450-457: LGTM! Clear naming and addition of compressed benchmark variant.

The new benchmark names BenchmarkReceive10kRows and BenchmarkReceive10kRowsCompressed clearly indicate what's being tested. Adding a compressed variant provides valuable performance comparison insights.

@coveralls
Copy link

coveralls commented Apr 23, 2025

Coverage Status

coverage: 82.833%. remained the same
when pulling 3cb6049 on methane:fix-bench-massiverows
into 7da50ff on go-sql-driver:master.

@methane methane force-pushed the fix-bench-massiverows branch from 89859a2 to 3cb6049 Compare April 23, 2025 08:14
@methane methane merged commit f7d94ec into go-sql-driver:master Apr 23, 2025
38 checks passed
@methane methane deleted the fix-bench-massiverows branch April 23, 2025 08:28
methane added a commit to methane/mysql that referenced this pull request Apr 23, 2025
* Rename BenchmarkReceiveMassiveRows to BenchmarkReceive10kRows
* Add BenchmarkReceive10kRowsCompress that run BenchmarkReceiveMassiveRows with compression
* Other tiny benchmark improvements.
methane added a commit to methane/mysql that referenced this pull request Apr 23, 2025
* Rename BenchmarkReceiveMassiveRows to BenchmarkReceive10kRows
* Add BenchmarkReceive10kRowsCompress that run BenchmarkReceiveMassiveRows with compression
* Other tiny benchmark improvements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants