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

perf: replace ahash with gxhash #44

Closed
wants to merge 3 commits into from
Closed

Conversation

shenxiangzhuang
Copy link
Owner

@shenxiangzhuang shenxiangzhuang commented May 14, 2024

Summary by CodeRabbit

  • Refactor
    • Improved performance by switching from AHashMap to GxHashMap for storing ngram counts.
    • Updated internal data structures in key functions to use GxHashMap for more efficient memory usage.

@shenxiangzhuang shenxiangzhuang added the enhancement New feature or request label May 14, 2024
@shenxiangzhuang shenxiangzhuang self-assigned this May 14, 2024
Copy link
Contributor

coderabbitai bot commented May 14, 2024

Warning

Rate Limit Exceeded

@shenxiangzhuang has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 7 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 7176a90 and ef6af20.

Walkthrough

The recent update involves transitioning from the ahash crate to the gxhash crate project-wide. Specifically, the shift from AHashMap to GxHashMap in functions managing ngram counts in bleu.rs and ngram.rs files aims to enhance performance or compatibility by leveraging gxhash features.

Changes

File Path Change Summary
Cargo.toml Replaced ahash = "0.8.11" with gxhash = "3.0.0".
src/bleu.rs Switched from AHashMap to GxHashMap in the compute_score function.
src/ngram.rs Replaced std::collections::HashMap with GxHashMap in get_token_ngram_counter.

🐇
In the land of code, a swap was made,
From ahash to gxhash, a new parade.
Ngrams now in a different map,
GxHashMap takes the lap.
Performance shines, bugs evade,
In the rabbit's den, progress displayed. 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 97da600 and 2d054ad.
Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • src/bleu.rs (2 hunks)
  • src/ngram.rs (1 hunks)
Additional comments not posted (4)
Cargo.toml (1)

23-23: Dependency change from ahash to gxhash looks good and is aligned with the PR's objectives.

src/ngram.rs (2)

2-2: Switch to GxHashMap from gxhash crate is consistent with the project-wide changes.


6-7: The function get_token_ngram_counter now uses GxHashMap for ngram counting. Ensure that all usages of this function are compatible with the new return type.

Verification successful

The function get_token_ngram_counter is used in src/bleu.rs and the operations on its return type GxHashMap<&[String], usize> are compatible with the new return type. The code correctly handles the hashmap operations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `get_token_ngram_counter` handle the new return type correctly.

# Test: Search for the function usage. Expect: Only occurrences of the new return type.
rg --type rust $'get_token_ngram_counter'

Length of output: 657



Script:

#!/bin/bash
# Extract lines around the usage of `get_token_ngram_counter` in `src/bleu.rs` to verify handling of the new return type.
rg -A 5 -B 5 'get_token_ngram_counter' src/bleu.rs

Length of output: 948

src/bleu.rs (1)

64-64: Replacement of AHashMap with GxHashMap in compute_score function aligns with the new hashing strategy. Ensure the performance characteristics meet the project's requirements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2d054ad and 7176a90.
Files selected for processing (1)
  • Cargo.toml (1 hunks)
Additional comments not posted (1)
Cargo.toml (1)

23-23: Dependency on gxhash added as expected.

Ensure that gxhash version "3.0.0" is compatible with the project's existing dependencies and Rust edition.

Verification successful

Dependency on gxhash version "3.0.0" is compatible with the project's existing dependencies and Rust edition.

  • lazy_static version "^1.4" includes version "1.4.0".
  • No specific Rust version requirement for gxhash implies compatibility with Rust edition "2021".
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for any known compatibility issues between gxhash 3.0.0 and other dependencies.

# Test: Search for compatibility issues in the Rust community repositories or issue trackers.
echo "Check Rust community forums and GitHub issues for 'gxhash 3.0.0 compatibility'."

Length of output: 174



Script:

#!/bin/bash
# List all dependencies in Cargo.toml
echo "Dependencies in Cargo.toml:"
grep -E '^\s*[a-zA-Z0-9_-]+\s*=\s*".*"$' Cargo.toml

# Check the Rust edition specified in Cargo.toml
echo "Rust edition in Cargo.toml:"
grep -E '^\s*edition\s*=\s*".*"$' Cargo.toml

Length of output: 601



Script:

#!/bin/bash
# Check for known compatibility issues between gxhash 3.0.0 and other dependencies
dependencies=("cached" "regex" "lazy_static" "counter" "rayon")
for dep in "${dependencies[@]}"; do
  echo "Searching for compatibility issues between gxhash 3.0.0 and $dep..."
  curl -s "https://crates.io/api/v1/crates/gxhash/3.0.0/dependencies" | jq -r '.dependencies[] | select(.crate_id == "'$dep'") | .req'
done

# Verify if gxhash 3.0.0 supports Rust edition 2021
echo "Checking if gxhash 3.0.0 supports Rust edition 2021..."
curl -s "https://crates.io/api/v1/crates/gxhash/3.0.0" | jq -r '.rust_version'

Length of output: 1863



Script:

#!/bin/bash
# Check if lazy_static version "^1.4" includes version "1.4.0"
echo "Checking if lazy_static version '^1.4' includes version '1.4.0'..."
cargo search lazy_static --limit 10 | grep -E '^lazy_static = "1.4.0"$'

# Check general compatibility of gxhash with Rust edition 2021
echo "Checking general compatibility of gxhash with Rust edition 2021..."
curl -s "https://crates.io/api/v1/crates/gxhash" | jq -r '.versions[] | select(.num == "3.0.0") | .rust_version'

Length of output: 562



Script:

#!/bin/bash
# Check if lazy_static version "^1.4" includes version "1.4.0" using an alternative method
echo "Checking if lazy_static version '^1.4' includes version '1.4.0'..."
curl -s "https://crates.io/api/v1/crates/lazy_static" | jq -r '.versions[] | select(.num == "1.4.0") | .num'

# Check general compatibility of gxhash with Rust edition 2021
echo "Checking general compatibility of gxhash with Rust edition 2021..."
curl -s "https://crates.io/api/v1/crates/gxhash" | jq -r '.versions[] | select(.num == "3.0.0") | .rust_version'

Length of output: 530

Copy link

codecov bot commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.05%. Comparing base (16208a9) to head (ef6af20).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #44   +/-   ##
=======================================
  Coverage   85.05%   85.05%           
=======================================
  Files           4        4           
  Lines         368      368           
=======================================
  Hits          313      313           
  Misses         55       55           

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

@shenxiangzhuang shenxiangzhuang deleted the perf/gxhash branch July 22, 2024 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant