栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

刺激代码内联

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

刺激代码内联

报价Minux(2013年1月31日):

默认情况下,内联函数将尝试内联不调用紧急事件或恢复或选择或切换或创建闭包或执行/延迟函数的叶子函数(不调用其他函数/方法/接口)(请参见下面的示例),以及表示时,小于40个节点(大致对应40个简单操作)。但是请注意,这仅描述了gc编译器的当前状态,并且将来肯定会有所改善。因此,请尽量不要依赖于此。

在出现性能问题之前,您无需关心。内联与否,它将执行相同的操作。

如果性能确实很重要,并且可以带来显着且显着的变化,则不要依赖当前(或过去)的内联条件,自己“内联”它(不要将其放在单独的函数中)。

规则可以在

$GOROOT/src/cmd/compile/internal/gc/inl.go
文件中找到。您可以使用
'l'
调试标志来控制其积极性。

// The inlining facility makes 2 passes: first caninl determines which// functions are suitable for inlining, and for those that are it// saves a copy of the body. Then inlcalls walks each function body to// expand calls to inlinable functions.//// The debug['l'] flag controls the aggressiveness. Note that main() swaps level 0 and 1,// making 1 the default and -l disable.  -ll and more is useful to flush out bugs.// These additional levels (beyond -l) may be buggy and are not supported.//      0: disabled//      1: 40-nodes leaf functions, oneliners, lazy typechecking (default)//      2: early typechecking of all imported bodies//      3: allow variadic functions//      4: allow non-leaf functions , (breaks runtime.Caller)////  At some point this may get another default and become switch-offable with -N.////  The debug['m'] flag enables diagnostic output.  a single -m is useful for verifying//  which calls get inlined or not, more is for debugging, and may go away at any point.

另请查看博客文章:Dave Cheney-使Go快速发展的五件事(2014-06-07),其中写了关于内联的内容(长篇文章,大约在中间,搜索“内联”词)。

关于内联改进(也许是1.9吗?)的有趣讨论:cmd /
compile:改进内联成本模型#17566



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/469014.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号