What is fast path, slow path, hot path

huangapple go评论69阅读模式
英文:

What is fast path, slow path, hot path

问题

fast pathslow pathhot path是在Go源代码中经常出现的三个术语。

  • fast path(快速路径):指的是在程序执行过程中,经常被执行的代码路径。这些路径通常是高效的,因为它们被频繁使用,所以需要尽可能地优化和加速。在Go中,fast path通常用于处理常见的情况,以提高程序的性能。

  • slow path(慢速路径):指的是在程序执行过程中,相对不常执行的代码路径。这些路径可能涉及更复杂的逻辑或者需要更多的计算资源。相比于fast pathslow path的执行速度可能较慢。

  • hot path(热路径):指的是在程序执行过程中,频繁被执行且对性能影响较大的代码路径。这些路径通常是程序的瓶颈所在,对于性能优化非常关键。在Go中,hot path通常是指那些被高频调用的函数或方法。

这些术语并不是Go语言特有的,它们在其他编程语言中也有类似的概念。它们的使用主要是为了描述代码执行路径的不同特性和性能优化的需求。

英文:

I've been reading Go source code for a while , there are three terms which is fast path,slow path, hot path comes up a lot.

So, my question is, what exactly is fast path,slow path, hot path ? Are these terms unique to Go ?

答案1

得分: 8

快速路径是指执行较少工作的路径,而慢速路径是指执行更多工作的路径。例如,向哈希映射表中添加一个值时,将该值直接放入空桶中是快速路径,而增加桶的数量、将所有值复制到新位置,然后再插入新值是慢速路径。当添加浮点数时,其中一个数是非规格化数的情况是慢速路径,比处理普通数的路径慢得多。"路径"的概念表明对于给定的函数,根据情况或提供的值,可能发生其中任何一种情况;这不是选择快速或慢速的问题。

"热"路径是指大部分时间都会执行的路径,而"冷"路径是指很少执行的路径。热路径是优化的重点,因为程序大部分时间都在这里执行。当热路径也是快速路径,而慢速路径也是冷路径时,就会出现幸福感。

这些概念并不特定于Go语言;它们是计算机领域常见的术语。

英文:

A fast path is a path that's fast (i.e. does less work), and a slow path is a path that's slow (i.e. does more work). For example, when adding a value to a hashmap, just sticking the value into an empty bucket is the fast path, while increasing the number of buckets, copying all of the values to their new locations, then inserting the new value is the slow path. When adding floating point numbers, the case where one of them is a denormal is a slow path, many times slower than the path for ordinary numbers. The notion of "paths" indicates that either one could happen for a given function, depending on circumstances or on the value provided; it's not a choice of being fast or slow.

A "hot" path is one that's taken most of the time, while a "cold" path is one that's taken only rarely. Hot paths are good targets for optimization, because they are where a program spends most of its time. Happiness occurs when the hot path is also the fast path, and the slow paths are also cold.

None of this is specific to Go; it's common terminology in computing.

huangapple
  • 本文由 发表于 2021年8月27日 10:07:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/68947219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定