Skip to content

Comments

使用尾递归优化编译时栈深度过大的问题#132

Open
DQinYuan wants to merge 2 commits intoalibaba:branch_version_3.x.xfrom
DQinYuan:fix-stack-overflow
Open

使用尾递归优化编译时栈深度过大的问题#132
DQinYuan wants to merge 2 commits intoalibaba:branch_version_3.x.xfrom
DQinYuan:fix-stack-overflow

Conversation

@DQinYuan
Copy link
Collaborator

@DQinYuan DQinYuan commented Mar 28, 2021

和 issue #120 相关

虽然在 3.2.1 时 qlexpress 似乎优化过一次栈的使用,但是依旧栈的深度依旧很深,比如下面一段简单的脚本,最大栈的深度就高达 152:

if (prod in ("xxx", "yyy")
        && (((product == "standard" || product == "phase_standard") && (bizIdentity == "1111" || bizIdentity == "44555"))
            || (productCode == "fack" && bizIdentity == "1212")
            || (productCode == "auth" && bizIdentity == "3323"))) {
            return "TTTTT";
    }

线上稍微长一些的脚本就有很大的 stackOverflow 风险。所以我这里将语法分析部分改成了尾递归,跑过了所有单测,能够彻底解决编译栈深度过深的问题

@DQinYuan
Copy link
Collaborator Author

DQinYuan commented Apr 1, 2021

Benchmark Mode Samples Score Score error Units
优化前 thrpt 20 858.748 31.298 ops/s
优化后 thrpt 20 1275.797 21.940 ops/s

经过测试,编译性能有大幅度提升

@baoxingjie
Copy link
Contributor

我自己研究下,谢谢你的建议

@fjfyitian
Copy link

我们也遇到类似的问题,请问这个issue可以关了吗?谢谢!

@zhengshengjun1125
Copy link

这个问题在4x版本修复了吗?我这边好像遇到了 如果表达式里面的条件太多 cpu好像就爆了 看着好像是ast解析出现了问题

@haycco
Copy link

haycco commented Jan 16, 2026

最新的版本 4.0.9 这个问题依旧存在啊

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.

5 participants