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

chore: update derive_more and fastnum #106

Merged
merged 2 commits into from
Feb 5, 2025
Merged

chore: update derive_more and fastnum #106

merged 2 commits into from
Feb 5, 2025

Conversation

shuhuiluo
Copy link
Collaborator

@shuhuiluo shuhuiluo commented Feb 5, 2025

Upgraded derive_more to v2 with new features and fastnum to v0.1.11, adjusting included features. Increased package version to 4.0.0-rc4 to reflect these updates.

Summary by CodeRabbit

  • Chores
    • Upgraded the core package to version 4.0.0-rc4 for improved system reliability.
    • Updated key dependencies to incorporate additional features and ensure robust performance.
  • Documentation
    • Enhanced the README with clearer code snippets and improved structure for better readability.
  • Refactor
    • Changed internal data structures from FxHashMap to HashMap for better performance consistency across various components.

Upgraded `derive_more` to v2 with new features and `fastnum` to v0.1.11, adjusting included features. Increased package version to 4.0.0-rc4 to reflect these updates.
@shuhuiluo shuhuiluo requested a review from malik672 February 5, 2025 04:41
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The pull request updates dependency configurations in the Cargo.toml file, including a version bump from 4.0.0-rc3 to 4.0.0-rc4. The derive_more dependency is updated to version 2, adding the from feature alongside the existing deref feature. The fastnum dependency is updated from 0.1.9 to 0.1.11, removing the libm feature while retaining numtraits. Additionally, various struct fields and type definitions are changed from FxHashMap to HashMap across multiple source files.

Changes

File Summary
Cargo.toml Updated package version; Modified derive_more dependency to version 2 with added from feature; Updated fastnum version and removed libm feature; Updated num-integer version and added new num-traits dependency; Updated std feature to include additional imports.
README.md Enhanced formatting and content; Updated code snippets for syntax highlighting; Expanded Token instance example for clarity; Adjusted license section path.
src/addresses.rs Changed AddressMap and CHAIN_TO_ADDRESSES_MAP from FxHashMap to HashMap.
src/entities/weth9.rs Updated tokens field in WETH9 struct from FxHashMap to HashMap; Adjusted instantiation in new method.
src/lib.rs Replaced initial documentation comment with content from README.md; Simplified no_std conditional compilation; Updated imports and re-exported items; Modified examples module conditional compilation.
src/utils/sorted_insert.rs Added import statement for alloc::vec in the test module; No changes to the core logic of sorted_insert.

Possibly related PRs

Suggested reviewers

  • malik672

Poem

I'm a bunny on the run,
Hopping over code changes in the sun,
Version bumps and feature tweaks in sight,
Quick hops through Cargo.toml delight,
Celebrating each update with a joyful byte!
🐰✨

Tip

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

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.

@shuhuiluo shuhuiluo marked this pull request as draft February 5, 2025 05:03
… with `HashMap`

Updated dependencies to use non-default features and introduced `default = []` in features. Replaced `FxHashMap` with standard `HashMap` for better compatibility. Refactored documentation and examples for clarity, aligning the library's setup with best practices for no-std support.
@shuhuiluo shuhuiluo marked this pull request as ready for review February 5, 2025 06:20
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)
README.md (1)

60-66: Refine macro invocation syntax.
Consider removing the extra spacing in the macro calls (e.g., change println ! ( to println!() to adhere to idiomatic Rust syntax. This small style refinement will improve the readability of the example.

-    Ok(true) => println ! ("DAI sorts before ETH"),
-    Ok(false) => println ! ("DAI does not sort before ETH"),
-    Err(e) => println ! ("Error comparing tokens: {:?}", e),
+    Ok(true) => println!("DAI sorts before ETH"),
+    Ok(false) => println!("DAI does not sort before ETH"),
+    Err(e) => println!("Error comparing tokens: {:?}", e),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f219ce8 and 0b9f909.

📒 Files selected for processing (6)
  • Cargo.toml (2 hunks)
  • README.md (3 hunks)
  • src/addresses.rs (2 hunks)
  • src/entities/weth9.rs (2 hunks)
  • src/lib.rs (4 hunks)
  • src/utils/sorted_insert.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/utils/sorted_insert.rs
🧰 Additional context used
🪛 LanguageTool
README.md

[style] ~86-~86: Using many exclamation marks might seem excessive (in this case: 5 exclamation marks for a text that’s 2495 characters long)
Context: ... Contribution Contributions are welcome! If you find a bug or have suggestions f...

(EN_EXCESSIVE_EXCLAMATION)

🔇 Additional comments (18)
Cargo.toml (3)

3-3: Version bump looks appropriate.

The version increment to 4.0.0-rc4 aligns with the dependency updates in this PR.


28-28: Good update to std feature dependencies.

The std feature now correctly includes all necessary standard library support for the dependencies.


15-23: Verify compatibility with derive_more v2.

The update to derive_more v2 is a major version change that could introduce breaking changes. Please ensure all derived traits continue to work as expected.

Dependencies are well-configured for no_std support.

Good practice setting default-features = false for the dependencies to support no_std environments.

Consider the impact of feature changes.

The removal of the libm feature from fastnum and its addition to num-traits suggests a refactor of floating-point operations. Ensure this change doesn't affect numerical precision or behavior.

src/lib.rs (3)

1-1: Good documentation practice.

Including the README.md content in the crate documentation improves visibility and maintainability.


21-21: Verify num_traits usage.

The addition of num_traits import with _ suggests it's used for its traits implementation. Ensure this doesn't conflict with existing numeric trait implementations.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for num_traits usage
rg "impl.*num_traits::" -A 5

Length of output: 30


🏁 Script executed:

#!/bin/bash
echo "Searching for all occurrences of 'num_traits' in the codebase (with file names and line numbers):"
rg "num_traits" -n

echo ""
echo "Searching for 'num_traits' occurrences in Cargo.toml (to verify dependency setup):"
rg "num_traits" Cargo.toml

Length of output: 483


NUM_TRAITS Usage Verified

The only reference to num_traits is in src/lib.rs as use num_traits as _;, which is a common pattern for importing traits solely for their implementations without binding them to an explicit name. No conflicting implementations or additional usage of num_traits were found in the codebase or in the dependency configuration (Cargo.toml), and there is no indication that this import interferes with other numeric trait implementations.


46-50: Consider performance implications of HashMap switch.

The change from FxHashMap to HashMap might impact performance as FxHashMap uses a faster hashing algorithm. Consider benchmarking if this is performance-critical code.

✅ Verification successful

🌐 Web query:

What are the performance differences between HashMap and FxHashMap in Rust?

Length of output: 5363


Performance Benchmarking Recommendation

The switch from using an optimized FxHashMap (which uses the fast FxHash algorithm) to the default HashMap (which uses SipHash for improved security) can indeed have performance implications. Specifically:

  • Speed vs. Security:

    • FxHashMap typically outperforms the default HashMap in many scenarios (up to 2–3× faster in benchmarks with integer keys) because FxHash is optimized for speed.
    • The default HashMap, using SipHash, provides robust collision protection, which may incur additional overhead.
  • Workload Considerations:

    • If the affected code is performance-critical and handles large numbers of entries or relies on fast hash operations (especially with primitive types), you may see a noticeable performance impact.
    • For use cases with untrusted input or where collision resistance is paramount, the performance trade-off for security is acceptable.
  • Recommendation:

    • Benchmark the relevant code paths (using tools like Criterion) to measure if the slower default HashMap affects your application's performance in a critical way.
    • If the performance hit is unacceptable and the security trade-offs allow it (e.g., with trusted data), consider reverting to or conditionally using FxHashMap.

Based on the web research and documented performance differences, the review comment’s suggestion is valid.

src/entities/weth9.rs (1)

9-9: Consistent HashMap usage.

The change from FxHashMap to HashMap aligns with the changes in lib.rs. Since this is a static mapping of chain IDs to tokens, the performance difference should be negligible.

src/addresses.rs (1)

5-5: Consistent HashMap usage across address mappings.

The change from FxHashMap to HashMap for address mappings is consistent with other files. Since these are mostly static mappings used for lookups, the performance impact should be minimal.

Also applies to: 384-385

README.md (10)

15-18: Ensure README version consistency.
The Cargo.toml dependency snippet shows uniswap-sdk-core = "4.0.0", but the PR objectives indicate the package version was bumped to 4.0.0-rc4. Please confirm if this discrepancy is intentional or update the snippet to reflect the correct version.


22-24: Usage code snippet looks good.
The Rust snippet correctly imports the prelude using use uniswap_sdk_core::prelude::*; and is clearly formatted.


32-34: Improved example description.
The explanation now clearly states that the example demonstrates creating a new Token instance using the token! macro, enhancing clarity for users.


36-36: Enhanced details tag for improved UX.
The updated <summary> tag (“Click to expand”) improves content accessibility by providing a clear action for users to reveal the example details.


39-41: Clear import documentation.
The updated comment (// Import necessary preludes and token macro) alongside the import statement makes it clear that both the prelude modules and the token macro are being imported.


42-48: Well-documented token configuration.
The constants defining the chain ID, token address, decimals, symbol, and name are clearly set up with descriptive inline comments. This provides an excellent example for users on how to configure a token.


49-51: Effective demonstration of macro usage.
Using the token! macro to create a new Token instance is shown clearly, reinforcing how the macro should be utilized in user code.


52-55: Good demonstration of token method usage.
The snippet illustrating the use of methods like address() and is_native() is well presented and helps users understand how to interact with the token instance.


56-59: Clear example of token comparison.
The example showing token equality using two instances of the same token is clear and reinforces that two tokens instantiated identically are considered equal.


91-91: Improved license reference.
Changing the license link to [LICENSE](./LICENSE) ensures that users can reliably locate the license file from the repository root.

@shuhuiluo shuhuiluo merged commit 42e8959 into master Feb 5, 2025
3 checks passed
@shuhuiluo shuhuiluo deleted the dep branch February 5, 2025 07:04
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