-
Notifications
You must be signed in to change notification settings - Fork 39
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
Performance optimizations #3378
Closed
tudorpintea999
wants to merge
21
commits into
unionlabs:main
from
tudorpintea999:performance-optimizations
Closed
Performance optimizations #3378
tudorpintea999
wants to merge
21
commits into
unionlabs:main
from
tudorpintea999:performance-optimizations
+1,487
−2,402
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some small refactoring : -You don't need to clone name since it's already owned within the scope of Process -Move common paths like CIRCUIT_BASE_PATH and reusable command fragments to constants or helper functions to avoid duplication. -Use #[derive(Default)] for LogConfiguration and ShutdownConfig if applicable, instead of calling ::default() explicitly.
Current Issue: Hardcoded paths and configurations like LOGS_BASE_PATH and voyager-config.json are inflexible. Solution: Externalize configurations into a .toml, .yaml, or .json file and parse them during runtime using serde.
some small improvements: -Avoid clone in add_process: -Use Option::unwrap_or_else for better lazy evaluation -Add validation to ensure backoff_seconds is positive -Use static strings or references wherever possible for default values like "always" and "on_failure". -Leverage Enum for RestartPolicy.restart: instead of a string, use an enum for stricter type safety
Streamlined bar_color: Consolidated style construction with conditional modifications for efficiency and readability. Static Style in state_symbol_color: Used a static Style to avoid unnecessary object creation on each call. Const info_symbol: Used const for the info_symbol to reduce memory allocations and improve performance.
Static Names: Extracted static names like VOYAGER_QUEUE_NAME into constants for reusability and better readability. Reduced Repetition: Eliminated redundant calls to queue_process and migrations_process by reusing their names. Helper Functions: Introduced exec_probe and http_probe for concise and consistent probe creation. Efficient Dependency Handling: Used extend to populate depends_on for the relay process in a single operation. Improved Maintainability: Constants like CONFIG_PATH make future updates easier.
Error Handling: Replaced panics with proper Result propagation. Modularization: Extracted repeated logic into helper functions. Graceful Shutdown: Added signal handling to stop the server and worker gracefully. Reusable Query Helpers: Created fetch_pending_requests for database queries to reduce duplication. Worker Robustness: Added logs and clear handling for worker tasks. Improved Logging: Unified logging initialization based on configuration.
• Replaced unwrap with proper Result propagation for better error reporting. • Added meaningful error messages in initialize_provider and initialize_tendermint_client. • Replaced println! with tracing for consistent logging. • Extracted initialize_provider and initialize_tendermint_client to make do_main cleaner. • Abstracted block processing logic into process_blocks. • Made the block limit configurable via a command-line argument. • Added error handling for the Tendermint driver task to avoid silent failures.
Replaced .unwrap() with proper error propagation (?). • Extracted filtering logic to filter_transactions. • Added fetch_active_contracts for fetching active contracts. • Added structured logging with more context (e.g., block height, contract address). • Removed potential panics by ensuring safe conversions and logging errors instead of unwinding.
• Extracted logic into smaller helper functions like process_unmapped_clients, process_single_client, and insert_client for better readability and reuse. • Replaced .unwrap() with proper error propagation using Result and custom error handling. • Added structured and contextual logging to provide better observability into processing steps and errors. • Centralized string parsing and decoding logic to prevent repetitive conversions. • Improved tick interval management with tokio::interval.
• Added structured error logging in fetch_block_insert and process_block. • Created a reusable process_block function to handle both insert and update. • Replaced .clone() in get_block_insert with &self and pattern matching for efficient access. • Improved log messages with structured fields (e.g., block_height, transaction_count) for better traceability. • Abstracted fetch_range stream creation for clarity. • Standardized logging and error propagation across all methods.
• Replaced .unwrap() and .expect() with proper error propagation. • Added fetch_block_details, fetch_eager_details, fetch_logs, and create_block_insert to modularize the code. • Improved log messages with structured fields (e.g., block selection, provider ID). • Abstracted log grouping logic into group_logs_by_transaction. • Encapsulated bloom filter matching logic into bloom_filter_matches
execute_race and execute_race_some encapsulate the logic for calling race or race_some, reducing repetition across methods. • Added structured logging with tracing::error! to capture errors and the action that caused them. • Enhanced error handling by including the action name in error logs to improve debugging. • Removed repetitive conversions (provider_id.map(Into::into) and .map(Into::into)) by centralizing them in helper functions. • Standardized the structure of all public methods (get_chain_id, get_block, etc.). • Added inline comments to explain the purpose of methods and helper functions.
• Centralized logic for creating BlockReference using block_reference_from_parts. • Replaced .unwrap() with proper error propagation. • Moved block data insertion logic to insert_block_data for reuse and clarity. • Enhanced logs with structured context, such as block_reference, block_height, and event_count. • Avoided duplication in BlockReferenceProvider implementations by abstracting shared logic. • Simplified large methods like insert and update by delegating specific tasks to helper functions. • Refactored code for clarity and easier future enhancements.
• Replaced .expect() with .map_err for robust error handling. • Added structured error logging in execute_rpc. • Introduced execute_rpc to encapsulate repetitive RPC logic. • Centralized conversion logic to avoid redundancy. • Added structured logs for debugging and observability. • Simplified new method by separating client creation logic. • Ensured all RPC calls follow a uniform structure.
Centralized validation and error handling. Extracted reusable logic into helper functions. Improved logging with detailed messages. Added concurrency for block processing. Simplified deeply nested logic into smaller methods.
errors Added traits and derived additional ones (PartialEq, Hash). Simplified and standardized conversions using From/Into.
process_finalization, monitor_block_range, and finalize_block_range break down the large run_finalizer method into logical chunks. • Consolidated range end calculations into calculate_range_end. • Introduced sleep_with_backoff for consistent retry behavior.
• Extracted common logic for filtering and mapping clients into map_clients helper function. • Added structured logs with client_index and ?err for better error context. • Used expect with a meaningful fallback message to handle cases where no clients were available. • Renamed race_client_id to specific_client_id for better clarity. • Simplified flow by reducing repetitive patterns. • The shared helper function ensures that any future changes to client mapping logic only need to be made in one place.
• Used futures::stream::iter with buffer_unordered to fetch token lists concurrently. • Leveraged HashSet directly to store TokenInsert, which inherently removes duplicates. • Added detailed error logs for parsing and fetching issues. • Avoided .unwrap() by propagating errors. • Extracted map_valid_token for filtering tokens by valid chain IDs. • Included logs for token counts and process steps. • Reorganized logic for better readability and maintainability.
Centralized prefix-based hashing logic for consistency. Simplified complex iterator chains. Enhanced error messages for debugging. Reduced temporary allocations like buf. Improved readability with inline comments. Simplified hashing logic and used meaningful variable names.
@tudorpintea999 is attempting to deploy a commit to the unionbuild Team on Vercel. A member of the Team first needs to authorize it. |
this touches many unrelated areas of the repo, some of which are in active development (and thus are changing very often or are still actively being designed). please open issues for changes that you think would be worthwhile and we can discuss there. thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello !
During the past week i tried to improve your code
I made some commits,
It s not much but it s honest work and I hope it helps UNION>
Br,
Tudor.