LAC 应该优化
- Dominant language
- C++
- Stars
- 4k
- Forks
- 592
- PR merge metrics
- No merged PRs in 30d
Description
LAC 已经很不错了,但是应该还有值得优化的地方, 这里讨论C++版。 Python 是不是内部使用的C++? 不太知道.
LAC 对象一大堆内部数据, 其中
_predictor 是预测器, 不知道这个 PaddlePredictor 是否是有状态的。如果是有状态的, 只能目前这样了。我看百度设计不至于如此。
一般来说, 应该有两个概念, model 与 parser(或 matcher, searcher, 怎么叫都行)。 前者是模型,代表训练的数据组成的网络模型, 应该是加载后其他 parser 共享这个模型。 要求这里面的数据都是无状态的。
然后parser 包括模型的引用,输入数据, parse 的中间数据或结果。 这个可以是有状态的。
model 很大时尤其需要这样设计。
现在C++ 版核心只有一个 LAC,混合包括了模型, parse 输入输出, 这样多个实例无法共享其中较大的数据。
结果为了线程安全, 每次使用时都 clone 一个LAC, 这大大增加了内存消耗。
当然如果模型极小 这无所谓, 但是不要忘记, 还有 定制词典。这个有可能不小, 难道每次使用这些都要clone 一下吗。
总结:
现在的版本, 要想安全使用, 每个线程都需要完全clone 一个lac
理想情况
主线程加载一个 model
其他线程 每次使用 创建一个parser(线程池情况,也可以每个线程只创建一次),传入model 参数。
其他大多数类似系统都是这么设计的。 为何 LAC 不呢?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the C++ LAC implementation around _predictor and PaddlePredictor, focusing on how model data, parser state, custom dictionaries, and cloning are handled. Compare the current single-object design with the proposed shared model and per-thread parser design; done means the ownership, thread-safety, and memory-sharing behavior are defined and covered by relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100