Skip to content

Conversation

@sborovinsky
Copy link

Summary

This optimization caches compiled regex patterns in SizeAndTimeBasedArchiveRemover to avoid repeated pattern compilation for the same time period, which improves performance during log file cleanup operations.

Changes

  • Added a static ConcurrentHashMap to store regex patterns
  • Added helper method to retrieve or create regex patterns
  • Modified getFilesInPeriod to use cached patterns
  • Preserved existing behavior for descendingSort method

Testing

  • Added a new test case testPatternCaching that verifies the caching mechanism works
  • Ran existing SizeAndTimeBasedArchiveRemoverTest tests to ensure compatibility
  • All tests pass without modification to existing behavior
  • Maintained backward compatibility with existing test expectations

Benefits

The implementation caches regex patterns when they're compiled, using the regex string as the key. This optimization is particularly beneficial during log cleanup operations, when the same patterns are repeatedly used, avoiding the overhead of regex compilation.

The performance improvement will be most noticeable when:

  • Multiple cleanup operations occur during the application lifetime
  • Log files are split frequently, leading to more cleanup passes
  • The system has many log files to process during each cleanup cycle

This change is minimal and focused, only modifying the necessary components without disrupting the existing functionality.

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.

1 participant