Repository navigation
Convert all regexes to source-generated regexes - #7
Merged
Merged
Conversation
RegexOptions.Compiled depends on Reflection.Emit at first use, which is unavailable under NativeAOT - there the engine silently falls back to the slow interpreter, and the hottest pattern (the CJK block splitter that runs on every Cut) pays that cost on every match. Generated regexes emit plain matching code that AOT compiles natively, and they also remove the lazy per-pattern compile cost from first use. Also delete two regexes that no longer have references.
Member
Author
|
This file contains hidden or 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
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.
概述
将全部 17 处
RegexOptions.Compiled正则迁移为[GeneratedRegex]源生成版本(JiebaSegmenter 5、PosSegmenter 7、FinalSeg Viterbi 2、Extensions 1,删除 2 个无引用正则)。动机
RegexOptions.Compiled依赖首次使用时的 Reflection.Emit,NativeAOT 下不可用并静默回退到解释执行。最热的 CJK 分块正则(每次Cut都在 Split+IsMatch)在 AOT 发布里一直跑的是慢速解释器;源生成版本是纯 C# 匹配代码,AOT 下原生全速。TFM 已只剩 net8.0/net10.0,
[GeneratedRegex](C# 11/net7+)的版本障碍不再存在。JiebaSegmenter/PosSegmenter/Viterbi/Extensions转为 partial,调用点由字段访问改为方法调用;删除已无引用的RegexEnglishChars与RegexNewline。验证