Page 234 - 《软件学报》2026年第3期
P. 234

软件学报 ISSN 1000-9825, CODEN RUXUEW                                        E-mail: jos@iscas.ac.cn
                 2026,37(3):1197−1224 [doi: 10.13328/j.cnki.jos.007464] [CSTR: 32375.14.jos.007464]  http://www.jos.org.cn
                 ©中国科学院软件研究所版权所有.                                                          Tel: +86-10-62562563



                                                                        *
                 Go  语言程序的内存性能与安全问题实证研究

                 李清伟,    丁伯尧,    张    昱,    陈金宝


                 (中国科学技术大学 计算机科学与技术学院, 安徽 合肥 230026)
                 通信作者: 张昱, E-mail: yuzhang@ustc.edu.cn

                 摘 要: 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; 内存性能; 静态代码分析; 内存安全; 实证研究
                 中图法分类号: TP311

                 中文引用格式: 李清伟, 丁伯尧, 张昱, 陈金宝. Go语言程序的内存性能与安全问题实证研究. 软件学报, 2026, 37(3): 1197–1224.
                 http://www.jos.org.cn/1000-9825/7464.htm
                 英文引用格式: Li QW, Ding BY, Zhang Y, Chen JB. Empirical Study of Memory Performance and Safety Issues of Golang Programs.
                 Ruan Jian Xue Bao/Journal of Software, 2026, 37(3): 1197–1224 (in Chinese). http://www.jos.org.cn/1000-9825/7464.htm

                 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


                 *    基金项目: 国家自然科学基金 (62272434)
                  收稿时间: 2024-12-09; 修改时间: 2025-02-17, 2025-04-16; 采用时间: 2025-05-06; jos 在线出版时间: 2026-01-14
                  CNKI 网络首发时间: 2026-01-15
   229   230   231   232   233   234   235   236   237   238   239