Go语言程序的内存性能与安全问题实证研究
作者:
作者单位:

作者简介:

通讯作者:

中图分类号:

TP311

基金项目:

国家自然科学基金 (62272434)


Empirical Study of Memory Performance and Safety Issues of Golang Programs
Author:
Affiliation:

Fund Project:

  • 摘要
  • |
  • 图/表
  • |
  • 访问统计
  • |
  • 参考文献
  • |
  • 相似文献
  • |
  • 引证文献
  • |
  • 资源附件
  • |
  • 文章评论
    摘要:

    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个得到了肯定回复.

    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.

    参考文献
    相似文献
    引证文献
引用本文

李清伟,丁伯尧,张昱,陈金宝. Go语言程序的内存性能与安全问题实证研究.软件学报,2026,37(3):1197-1224

复制
相关视频

分享
文章指标
  • 点击次数:
  • 下载次数:
  • HTML阅读次数:
  • 引用次数:
历史
  • 收稿日期:2024-12-09
  • 最后修改日期:2025-02-17
  • 录用日期:
  • 在线发布日期: 2026-01-14
  • 出版日期: 2026-03-06
文章二维码
您是第位访问者
版权所有:中国科学院软件研究所 京ICP备05046678号-3
地址:北京市海淀区中关村南四街4号,邮政编码:100190
电话:010-62562563 传真:010-62562533 Email:jos@iscas.ac.cn
技术支持:北京勤云科技发展有限公司

京公网安备 11040202500063号