Skip to content

perf: Optimize has_more_than_n_keys function and BatchTraceProcessor #143

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

Closed

Conversation

tongshu1943
Copy link

Feature Description

Implemented performance optimizations in two key areas of the codebase:

  1. Replaced inefficient key counting method in has_more_than_n_keys function with a more efficient approach
  2. Optimized the BatchTraceProcessor class to improve trace and span export performance

Specific Improvements

  1. Modified has_more_than_n_keys function to use len(obj) directly instead of iterating through keys
  2. Optimized _export_batches method to reduce queue checks and improve batching logic
  3. Added tests to verify the optimized functions work correctly

Technical Implementation

  • Dictionary key counting: Using len(obj) directly is more efficient than iterating through all keys
  • Trace batch processing: Reduced the number of queue checks and improved the batching logic
  • Both optimizations maintain existing behavior without introducing regressions
  • Added comprehensive test coverage for the optimized functions

Testing

  • Added test file test_has_more_than_n_keys.py to verify the optimized function
  • All tests pass, confirming the optimizations work correctly
  • All type checks and lint checks pass

Co-Authored-By: Juntong CHEN <i@chenjuntong.com>
@seratch
Copy link
Member

seratch commented Aug 15, 2025

Thanks for sending this pull request. We haven't observed performance issues here, so let us close this PR now.

@seratch seratch closed this Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants