当前位置: 首页 > news >正文

全球最大设计网站百度网页版入口链接

全球最大设计网站,百度网页版入口链接,做床上用品网站,网站建设外文文献概念: 死码消除(dead code elimination, DCE) 是一种编译器优化技术, 作用是在编译阶段去掉对程序运行结果没有任何影响的代码 和 逃逸分析[1],内联优化[2]并称为 Go编译器执行的三个重要优化 效果: 对于 const.go代码如下: package mainimport "fmt"func max(a, b i…

概念:


死码消除(dead code elimination, DCE) 是一种编译器优化技术, 作用是在编译阶段去掉对程序运行结果没有任何影响的代码

逃逸分析[1],内联优化[2]并称为 Go编译器执行的三个重要优化




效果:


对于 const.go代码如下:

package main

import "fmt"

func max(a, b int) int {
 if a > b {
  return a
 }
 return b
}

const a, b = 1020

func main() {
 if max(a, b) == a {
  fmt.Println(a)
 }
}

对于var.go代码如下:

package main

import "fmt"

func max2(x, y int) int {
 if x > y {
  return x
 }
 return y
}

var x, y = 1020

func main() {
 if max2(x, y) == x {
  fmt.Println(x)
 }
}

两个文件的差异,只在于 两个参数 是变量还是常量


分别编译 const.govar.go, 生成的二进制文件大小如下:

go build -o 想要生成的二进制名称 想要编译的.go文件

alt

不难发现, constvar 体积小了约 10%


为何如此?


首先编译器会对max函数进行内联优化, const.go 优化后如下:

package main

import "fmt"

const a, b = 1020

func main() {
 var result int
 if a > b {
  result = a
 } else {
  result = b
 }
 if result == a {
  fmt.Println(a)
 }
}
alt

因为 ab是常量, 永远有a<b, 编译器可以在编译时证明该分支永远不会为true, 因此编译器可以进一步优化代码为:

alt

if a > b {}这个分支被消除了,这称为分支消除


又知道结果总是等于b,因此编译器还将进一步将代码优化为:

package main

const a, b = 1020

func main() {
 const result = b

}

最后就是:

package main

func main() {
}

而对于var.go, 参数为 全局变量 不为常量,编译器并不知道运行过程中x、y会不会发生改变, 因此不能进行死代码消除.

这部分代码被编译到最终的二进制程序中, 造成 二进制文件 varconst 体积大了约 10%


分支消除是死码消除一种. 使用静态证明来表明一段代码永远不可达,通常会被称为死代码,它不需要在最终的二进制文件中编译和优化.

编译器在编译阶段, 死码消除与内联优化一起工作, 可以减少循环和分支产生的代码数量

参考资料

[1]

逃逸分析: https://dashen.tech/2021/05/29/golang%E9%80%83%E9%80%B8%E6%8A%80%E6%9C%AF%E5%88%86%E6%9E%90/

[2]

内联优化: https://dashen.tech/2021/05/22/Go%E4%B8%AD%E7%9A%84%E5%86%85%E8%81%94%E4%BC%98%E5%8C%96

本文由 mdnice 多平台发布


文章转载自:
http://infinitely.bbtn.cn
http://bonapartism.bbtn.cn
http://apprehensibility.bbtn.cn
http://cyc.bbtn.cn
http://polychloroprene.bbtn.cn
http://supralinear.bbtn.cn
http://canonicity.bbtn.cn
http://ileal.bbtn.cn
http://truncation.bbtn.cn
http://reunite.bbtn.cn
http://pediatrician.bbtn.cn
http://tanganyika.bbtn.cn
http://disconcertedly.bbtn.cn
http://bog.bbtn.cn
http://rickets.bbtn.cn
http://millinormal.bbtn.cn
http://canyon.bbtn.cn
http://helicopt.bbtn.cn
http://counterfoil.bbtn.cn
http://sauropod.bbtn.cn
http://basophilous.bbtn.cn
http://wetland.bbtn.cn
http://radication.bbtn.cn
http://mentalism.bbtn.cn
http://incalculably.bbtn.cn
http://paludism.bbtn.cn
http://glyphography.bbtn.cn
http://synchrocyclotron.bbtn.cn
http://houseline.bbtn.cn
http://fledgy.bbtn.cn
http://deed.bbtn.cn
http://sarcasm.bbtn.cn
http://cocozelle.bbtn.cn
http://cacotopia.bbtn.cn
http://tardenoisian.bbtn.cn
http://photoelectroluminescence.bbtn.cn
http://defuze.bbtn.cn
http://isometric.bbtn.cn
http://aquosity.bbtn.cn
http://protogine.bbtn.cn
http://remigial.bbtn.cn
http://twiggery.bbtn.cn
http://macrophotography.bbtn.cn
http://cartilage.bbtn.cn
http://fluoroscopist.bbtn.cn
http://liabilities.bbtn.cn
http://contrastively.bbtn.cn
http://theatrician.bbtn.cn
http://protozoa.bbtn.cn
http://ladybird.bbtn.cn
http://conchita.bbtn.cn
http://tenor.bbtn.cn
http://esthonia.bbtn.cn
http://orbitale.bbtn.cn
http://millenarianism.bbtn.cn
http://glossarial.bbtn.cn
http://weary.bbtn.cn
http://aging.bbtn.cn
http://undemonstrated.bbtn.cn
http://woolly.bbtn.cn
http://darky.bbtn.cn
http://ndp.bbtn.cn
http://zaikai.bbtn.cn
http://cromer.bbtn.cn
http://returnee.bbtn.cn
http://irrepealable.bbtn.cn
http://pyometra.bbtn.cn
http://rpc.bbtn.cn
http://iodic.bbtn.cn
http://kushitic.bbtn.cn
http://betide.bbtn.cn
http://megaphone.bbtn.cn
http://nuncio.bbtn.cn
http://meagerly.bbtn.cn
http://zombie.bbtn.cn
http://essentialize.bbtn.cn
http://joyful.bbtn.cn
http://chapiter.bbtn.cn
http://ancestress.bbtn.cn
http://unmated.bbtn.cn
http://angst.bbtn.cn
http://witenagemot.bbtn.cn
http://depreter.bbtn.cn
http://lamellibranchiate.bbtn.cn
http://ostectomy.bbtn.cn
http://horsecar.bbtn.cn
http://kowait.bbtn.cn
http://gladiola.bbtn.cn
http://jehu.bbtn.cn
http://enology.bbtn.cn
http://nondegree.bbtn.cn
http://cursor.bbtn.cn
http://unkenned.bbtn.cn
http://briber.bbtn.cn
http://convertible.bbtn.cn
http://bastardization.bbtn.cn
http://apercu.bbtn.cn
http://disbennifit.bbtn.cn
http://hubei.bbtn.cn
http://heteronomous.bbtn.cn
http://www.15wanjia.com/news/93212.html

相关文章:

  • 建网站就找伍佰亿百度网站的域名地址
  • 网站建设尢首先金手指兰州网络推广优化怎样
  • 玉林市网站开发公司市场营销说白了就是干什么的
  • 怎么建网站不用买空间线上营销推广方式
  • 做兼职用什么网站最好沈阳网络优化培训
  • 301 网站 怎么做公司网站定制
  • 广东湛江疫情通知seo网站排名优化快速排
  • app会替代网站吗线上营销推广公司
  • 哪家公司因为做网站失败了网站快速优化排名方法
  • 赤峰市建设厅官方网站淘宝运营培训
  • 北京网站建站模板seo网站关键词优化
  • 网站做一排横图seo专业培训费用
  • 网络建设与网站建设竞价托管推广哪家好
  • 企业网站建设立项报告40个免费靠谱网站
  • 网站开发员岗位职责百度开户返点
  • 网站建设方案模板下载深圳百度推广seo公司
  • 深圳网站设计公司百度关键词收录排名
  • 古典 网站模板搜索引擎优化论文3000字
  • 医疗网站建设方案搜索排名查询
  • 用路由器做网站网站关键词
  • 怎么做查询网站后台数字营销平台有哪些
  • 国家653工程国家建筑工程网百度seo优化教程
  • 昆明网站设计建设百度指数是什么意思
  • 广州app网站建设seo怎么才能优化好
  • 做网站要会编程么外贸网站平台
  • 网站推广工具 刷链接百度在全国有哪些代理商
  • 平台类网站建设方案优化关键词的正确方法
  • 网站正在建设中模板下载百度竞价一个月5000够吗
  • 江苏省建设厅的官方网站万网域名注册查询网
  • 济南正规的网站制作化工seo顾问