Skip to content

Comments

feat:实现正则表达式编译缓存功能#3130

Closed
ban-xiu wants to merge 6 commits intoalibaba:masterfrom
ban-xiu:master
Closed

feat:实现正则表达式编译缓存功能#3130
ban-xiu wants to merge 6 commits intoalibaba:masterfrom
ban-xiu:master

Conversation

@ban-xiu
Copy link
Contributor

@ban-xiu ban-xiu commented Jan 9, 2026

-使用项目中已有的LRUCache支持正则表达式编译缓存

@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 9, 2026

hi, @hengyunabc PTAL

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a regex compilation cache feature to improve performance by avoiding repeated compilation of the same regular expressions. The implementation leverages the existing LRUCache class to cache compiled Pattern objects with a maximum capacity of 100 entries.

Key changes:

  • Added RegexCacheManager singleton class to manage cached Pattern objects using LRUCache
  • Modified RegexMatcher to use cached Pattern objects from RegexCacheManager instead of compiling on each use
  • Added comprehensive unit tests for the caching functionality including basic operations, LRU eviction, and cache clearing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
core/src/main/java/com/taobao/arthas/core/util/RegexCacheManager.java New singleton class implementing regex pattern caching with LRU eviction strategy, providing thread-safe pattern compilation and caching
core/src/main/java/com/taobao/arthas/core/util/matcher/RegexMatcher.java Refactored to use RegexCacheManager for pattern caching, changing from String.matches() to cached Pattern.matcher().matches()
core/src/test/java/com/taobao/arthas/core/util/RegexCacheManagerTest.java Comprehensive test suite covering cache operations, LRU eviction behavior, and edge cases like null/empty patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 9, 2026

已按建议修复

@hengyunabc
Copy link
Collaborator

感觉 正则的使用也不多。什么情况下会有性能瓶颈?

@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 9, 2026

某些复杂的正则表达式(如包含大量回溯的模式)匹配过程本身就很慢

@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 9, 2026

在某些场景需要重复多次中断再重新使用正则表达式方法

@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 10, 2026

例如,在我的场景下常用到的trace <复杂正则表达式> -n 1,这样性能有很好提升

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 10, 2026

已修复

hengyunabc added a commit that referenced this pull request Jan 12, 2026
Co-authored-by: lbs <2322701154@qq.com>
@hengyunabc
Copy link
Collaborator

已经合并了。

@hengyunabc hengyunabc closed this Jan 12, 2026
@ban-xiu
Copy link
Contributor Author

ban-xiu commented Jan 12, 2026

@hengyunabc 老师请帮忙看看这个吧 bytekit/pull/47

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