引用本文:李清伟,丁伯尧,张昱,陈金宝.Go语言程序的内存性能与安全问题实证研究.软件学报,2026,37(3):1197-1224
【打印本页】   【下载PDF全文】   查看/发表评论  【EndNote】   【RefMan】   【BibTex】
←前一篇|后一篇→ 过刊浏览    高级检索
本文已被:浏览 659次   下载 644 本文二维码信息
码上扫一扫!
分享到: 微信 更多
Go语言程序的内存性能与安全问题实证研究
李清伟, 丁伯尧, 张昱, 陈金宝
中国科学技术大学 计算机科学与技术学院, 安徽 合肥 230026
摘要:
Go语言 (Go programming language, Golang)作为一门新兴编程语言, 利用编译时的逃逸分析与运行时的垃圾回收实现了高效的内存自动管理, 同时提供了interface、slice、map等内建数据类型, 显著提升了开发效率和程序性能. 然而, 这些特性也带来与传统C/C++语言不同的内存性能与安全性挑战. 通过静态代码分析, 实证研究了Go语言程序的内存性能与安全问题. 通过设计基于CodeQL的GitHub开源代码分析框架PatStat, 利用声明式语言QL分析开源仓库中的内存性能相关的代码模式, 并辅助人工总结和自动检测内存安全问题. 研究涵盖Go程序的内存访问特征和安全问题模式. 在分析996个近1年内更新的Go语言开源项目后发现: Go程序中域访问和解引用操作在内存访问中占比较高, 分别为25.44%与17.63%, 意味着需要在程序分析或优化中关注域敏感性和指向分析. 此外, Go特有的interface类型转换引发的隐式内存分配也是程序优化的重点. 通过人工分析130个涉及内存泄漏、无效内存地址或空指针解引用、悬垂指针的Issues, 总结10类Issue模式, 其中悬垂指针问题在Go语言中较少见. 这些Issues通常需要约30天修复, 但大多只需修改数十行代码即可完成. 研究成果为优化Go语言程序和减缓内存安全问题提供了参考. 此外, 针对包含切片表达式赋值, 可能导致内存泄漏的Issue模式开发代码检查工具, 并在真实项目中报告了6个Issues, 其中1个得到了肯定回复.
关键词:  Go  内存性能  静态代码分析  内存安全  实证研究
DOI:10.13328/j.cnki.jos.007464
分类号:TP311
基金项目:国家自然科学基金 (62272434)
Empirical Study of Memory Performance and Safety Issues of Golang Programs
LI Qing-Wei, DING Bo-Yao, ZHANG Yu, CHEN Jin-Bao
School of Computer Science and Technology, University of Science and Technology of China, Hefei 230026, China
Abstract:
The Go programming language (Golang), as an emerging programming language, achieves efficient automatic memory management through compile-time escape analysis and runtime garbage collection. It also provides built-in data types such as interface, slice, and map, which significantly enhance development efficiency and program performance. However, these features also introduce memory performance and safety challenges that differ from those in traditional languages like C/C++. This study uses static code analysis to empirically study memory performance and safety problems in Go programs. The framework PatStat, designed based on CodeQL, is employed to analyze open-source repositories on GitHub. This framework uses the declarative language QL to examine code patterns related to memory performance in open-source repositories, facilitating both manual summarization and automatic detection of memory safety problems. The research covers memory access characteristics and patterns of memory safety problems. An analysis of 996 Go open-source projects, updated within the past year, reveals that field accesses and dereference operations account for significant portions of memory access in Go programs, at 25.44% and 17.63%, respectively. This indicates the importance of field sensitivity and points-to analysis in Go program analysis and optimization. Moreover, implicit memory allocation resulting from Go’s unique interface type conversions is another key area for optimization. Through manual analysis of 130 Issues involving memory leaks, invalid memory addresses or null pointer dereferences, and dangling pointers, the study identifies 10 Issue patterns, noting that dangling pointer problems are rare in Go. These Issues typically require around 30 days for resolution but often demand only a few dozen lines of code changes. The findings offer insights for optimizing Go programs and mitigating memory safety concerns. Furthermore, a linter is developed to detect the Issue pattern, which involves the assignment of a slice expression that may lead to memory leaks. This tool identifies 6 Issues in real-world projects, one of which receives positive feedback.
Key words:  Go  memory performance  static code analysis  memory safety  empirical study

引用本文:
【打印本页】   【下载PDF全文】   查看/发表评论  【EndNote】   【RefMan】   【BibTex】
←前一篇|后一篇→ 过刊浏览    高级检索
本文已被:浏览次   下载  
分享到: 微信 更多
摘要:
关键词:  
DOI:
分类号:
基金项目:
Abstract:
Key words: