feat:random_device调整为tls对象,减少栈空间占用#533
Open
zhou-bai wants to merge 3 commits into
Open
Conversation
lailongwei
requested changes
Jun 8, 2026
lailongwei
requested changes
Jun 8, 2026
lailongwei
approved these changes
Jun 8, 2026
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.
#525
LLBC_Random在默认构造时会使用std::random_device生成随机种子。原实现会在构造函数表达式中直接创建std::random_device临时对象,部分标准库实现中std::random_device对象体积较大,可能增加LLBC_Random默认构造期间的栈空间占用。在栈空间较小的线程、协程或高频构造场景下,这种额外栈占用没有必要,也不利于稳定性和性能观测。
改动内容
本次调整将默认随机种子生成逻辑从
LLBC_Random构造函数中拆出:__LLBC_GetDefaultRandomSeed(),统一负责生成默认随机种子。std::random_device调整为thread_local对象,避免每次默认构造LLBC_Random时在栈上创建临时std::random_device。影响范围
本次改动只影响
LLBC_Random默认种子的生成方式,不改变随机数生成算法,也不改变固定 seed 场景下的随机序列行为。固定 seed 构造仍然可以保证相同 seed 产生一致的随机序列。