{"id":307015,"date":"2020-07-16T03:00:23","date_gmt":"2020-07-16T03:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=307015"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=307015","title":{"rendered":"\u042f\u0437\u044b\u043a\u043e\u0432\u0430\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/511176\/\">\n<h2>\u041f\u0440\u0435\u043b\u044e\u0434\u0438\u044f<\/h2>\n<p>  \u042d\u0442\u043e \u0442\u0440\u0435\u0442\u044c\u044f \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u0441\u0435\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0430\u0441\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0435 \u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439, \u0441\u0442\u0435\u043a\u043e\u0432, \u043a\u0443\u0447, escape analysis \u0438 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\/\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0432 Go. \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u0435\u0439:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/05\/language-mechanics-on-stacks-and-pointers.html\" rel=\"nofollow\">Language Mechanics On Stacks And Pointers<\/a> (<a href=\"https:\/\/habr.com\/ru\/post\/496846\">\u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/a>)<\/li>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/05\/language-mechanics-on-escape-analysis.html\" rel=\"nofollow\">Language Mechanics On Escape Analysis<\/a> (<a href=\"https:\/\/habr.com\/ru\/post\/497994\/\">\u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/a>)<\/li>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/06\/language-mechanics-on-memory-profiling.html\" rel=\"nofollow\">Language Mechanics On Memory Profiling<\/a><\/li>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/06\/design-philosophy-on-data-and-semantics.html\" rel=\"nofollow\">Design Philosophy On Data And Semantics<\/a><\/li>\n<\/ol>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u044d\u0442\u043e \u0432\u0438\u0434\u0435\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430: <br \/>  <a href=\"https:\/\/engineers.sg\/video\/go-concurrency-live-gophercon-sg-2017--1746\" rel=\"nofollow\">DGopherCon Singapore (2017) \u2014 Escape Analysis<\/a><\/p>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043e\u0431\u0443\u0447\u0438\u043b \u043e\u0441\u043d\u043e\u0432\u0430\u043c escape analysis, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u0435\u043a\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u042f \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0432\u0430\u043c \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u0443\u0447\u0443. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0441 \u044d\u0442\u0438\u043c \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<a name=\"habracut\"><\/a><\/p>\n<h2>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/h2>\n<p>  \u042f \u0445\u043e\u0442\u0435\u043b \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u043f\u0430\u043a\u0435\u0442\u0435 io, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u0414\u0430\u043d \u043f\u043e\u0442\u043e\u043a \u0431\u0430\u0439\u0442\u043e\u0432, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 elvis \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 Elvis \u0441 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0431\u0443\u043a\u0432\u044b. \u041c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043a\u043e\u0440\u043e\u043b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u0438\u043c\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0441 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0431\u0443\u043a\u0432\u044b.<\/p>\n<p>  \u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: <a href=\"https:\/\/play.golang.org\/p\/n_SzF4Cer4\" rel=\"nofollow\">play.golang.org\/p\/n_SzF4Cer4<\/a><br \/>  \u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438: <a href=\"https:\/\/play.golang.org\/p\/TnXrxJVfLV\" rel=\"nofollow\">play.golang.org\/p\/TnXrxJVfLV<\/a><\/p>\n<p>  <i>\u0412 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0448\u0430\u044e\u0442 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0435\u043b\u0435\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 algOne, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 io. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e algTwo, \u0447\u0442\u043e\u0431\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430.<\/i><\/p>\n<p>  \u0412\u043e\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 algOne.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 1<\/p>\n<pre><code class=\"go\">Input: abcelvisaElvisabcelviseelvisaelvisaabeeeelvise l v i saa bb e l v i saa elvi selvielviselvielvielviselvi1elvielviselvis  Output: abcElvisaElvisabcElviseElvisaElvisaabeeeElvise l v i saa bb e l v i saa elvi selviElviselvielviElviselvi1elviElvisElvis<\/code><\/pre>\n<p>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 algOne.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 2<\/p>\n<pre><code class=\"go\"> 80 func algOne(data []byte, find []byte, repl []byte, output *bytes.Buffer) {  81  82     \/\/ Use a bytes Buffer to provide a stream to process.  83     input := bytes.NewBuffer(data)  84  85     \/\/ The number of bytes we are looking for.  86     size := len(find)  87  88     \/\/ Declare the buffers we need to process the stream.  89     buf := make([]byte, size)  90     end := size - 1  91  92     \/\/ Read in an initial number of bytes we need to get started.  93     if n, err := io.ReadFull(input, buf[:end]); err != nil {  94         output.Write(buf[:n])  95         return  96     }  97  98     for {  99 100         \/\/ Read in one byte from the input stream. 101         if _, err := io.ReadFull(input, buf[end:]); err != nil { 102 103             \/\/ Flush the reset of the bytes we have. 104             output.Write(buf[:end]) 105             return 106         } 107 108         \/\/ If we have a match, replace the bytes. 109         if bytes.Compare(buf, find) == 0 { 110             output.Write(repl) 111 112             \/\/ Read a new initial number of bytes. 113             if n, err := io.ReadFull(input, buf[:end]); err != nil { 114                 output.Write(buf[:n]) 115                 return 116             } 117 118             continue 119         } 120 121         \/\/ Write the front byte since it has been compared. 122         output.WriteByte(buf[0]) 123 124         \/\/ Slice that front byte out. 125         copy(buf, buf[1:]) 126     } 127 }<\/code><\/pre>\n<p>  \u042f \u0445\u043e\u0447\u0443 \u0437\u043d\u0430\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u043a\u0430\u043a\u043e\u0435 \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u043d\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043a\u0443\u0447\u0443. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a.<\/p>\n<h2>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433<\/h2>\n<p>  \u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e algOne \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0442\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 3<\/p>\n<pre><code class=\"go\">15 func BenchmarkAlgorithmOne(b *testing.B) { 16     var output bytes.Buffer 17     in := assembleInputStream() 18     find := []byte(&quot;elvis&quot;) 19     repl := []byte(&quot;Elvis&quot;) 20 21     b.ResetTimer() 22 23     for i := 0; i &lt; b.N; i++ { 24         output.Reset() 25         algOne(in, find, repl, &amp;output) 26     } 27 }<\/code><\/pre>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f go test \u0441 \u043a\u043b\u044e\u0447\u0430\u0441\u043c\u0438 -bench, -benchtime \u0438 -benchmem.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 4<\/p>\n<pre><code class=\"go\">$ go test -run none -bench AlgorithmOne -benchtime 3s -benchmem BenchmarkAlgorithmOne-8        2000000          2522 ns\/op       117 B\/op            2 allocs\/op<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f algOne \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442 2 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e 117 \u0431\u0430\u0439\u0442 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e. \u042d\u0442\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u044d\u0442\u0438 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<h2>\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0441\u043d\u043e\u0432\u0430, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0430 -memprofile.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 5<\/p>\n<pre><code class=\"go\">$ go test -run none -bench AlgorithmOne -benchtime 3s -benchmem -memprofile mem.out BenchmarkAlgorithmOne-8        2000000          2570 ns\/op       117 B\/op            2 allocs\/op<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0434\u0432\u0430 \u043d\u043e\u0432\u044b\u0445 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 6<\/p>\n<pre><code class=\"go\">~\/code\/go\/src\/...\/memcpu $ ls -l total 9248 -rw-r--r--  1 bill  staff      209 May 22 18:11 mem.out       (NEW) -rwxr-xr-x  1 bill  staff  2847600 May 22 18:10 memcpu.test   (NEW) -rw-r--r--  1 bill  staff     4761 May 22 18:01 stream.go -rw-r--r--  1 bill  staff      880 May 22 14:49 stream_test.go<\/code><\/pre>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 memcpu \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 algOne \u0444\u0430\u0439\u043b\u0430 stream.go \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 stream_test.go. \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0432\u0430 \u043d\u043e\u0432\u044b\u0445 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f mem.out \u0438 memcpu.test. \u0424\u0430\u0439\u043b mem.out \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044f, \u0430 \u0444\u0430\u0439\u043b memcpu.test, \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u0447\u0435\u0441\u0442\u044c \u043f\u0430\u043f\u043a\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c \u043f\u0440\u0438 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u044f.<\/p>\n<p>  \u0418\u043c\u0435\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 pprof \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u044f.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 7<\/p>\n<pre><code class=\"go\">$ go tool pprof -alloc_space memcpu.test mem.out Entering interactive mode (type &quot;help&quot; for commands) (pprof) _<\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u00ab\u043d\u0438\u0437\u043a\u043e \u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u0444\u0440\u0443\u043a\u0442\u043e\u0432\u00bb \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0446\u0438\u044e -alloc_space \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u043f\u0446\u0438\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e -inuse_space. \u042d\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432\u0430\u043c, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044e, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0438 \u043e\u043d\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0431\u0435\u0440\u0435\u0442\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044c.<\/p>\n<p>  \u0412 \u043e\u043a\u043d\u0435 \u0432\u0432\u043e\u0434\u0430 (pprof) \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e algOne \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b list. \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e(\u0438), \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 8<\/p>\n<pre><code class=\"go\">(pprof) list algOne Total: 335.03MB ROUTINE ======================== ...\/memcpu.algOne in code\/go\/src\/...\/memcpu\/stream.go  335.03MB   335.03MB (flat, cum)   100% of Total         .          .     78:         .          .     79:\/\/ algOne is one way to solve the problem.         .          .     80:func algOne(data []byte, find []byte, repl []byte, output *bytes.Buffer) {         .          .     81:         .          .     82: \/\/ Use a bytes Buffer to provide a stream to process.  318.53MB   318.53MB     83: input := bytes.NewBuffer(data)         .          .     84:         .          .     85: \/\/ The number of bytes we are looking for.         .          .     86: size := len(find)         .          .     87:         .          .     88: \/\/ Declare the buffers we need to process the stream.   16.50MB    16.50MB     89: buf := make([]byte, size)         .          .     90: end := size - 1         .          .     91:         .          .     92: \/\/ Read in an initial number of bytes we need to get started.         .          .     93: if n, err := io.ReadFull(input, buf[:end]); err != nil || n &lt; end {         .          .     94:       output.Write(buf[:n]) (pprof) _<\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u0435, \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u043d\u0430\u0435\u043c \u0447\u0442\u043e input \u0438 buf \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 input \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439-\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bytes.Buffer, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c input. \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 input \u0438 \u043f\u043e\u0439\u043c\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 bytes.NewBuffer \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bytes.Buffer, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 flat (\u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 pprof) \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043c\u043d\u0435, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f algOne \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432\u044b\u0439\u0442\u0438 \u0432 \u043a\u0443\u0447\u0443.<\/p>\n<p>  \u042f \u0437\u043d\u0430\u044e, \u0447\u0442\u043e \u0441\u0442\u043e\u043b\u0431\u0435\u0446 flat \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 list \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Benchmark, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 algOne.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 9<\/p>\n<pre><code class=\"go\">(pprof) list Benchmark Total: 335.03MB ROUTINE ======================== ...\/memcpu.BenchmarkAlgorithmOne in code\/go\/src\/...\/memcpu\/stream_test.go         0   335.03MB (flat, cum)   100% of Total         .          .     18: find := []byte(&quot;elvis&quot;)         .          .     19: repl := []byte(&quot;Elvis&quot;)         .          .     20:         .          .     21: b.ResetTimer()         .          .     22:         .   335.03MB     23: for i := 0; i &lt; b.N; i++ {         .          .     24:       output.Reset()         .          .     25:       algOne(in, find, repl, &amp;output)         .          .     26: }         .          .     27:}         .          .     28: (pprof) _<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 cum (\u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446) \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u044d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043c\u043d\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f Benchmark \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0412\u0441\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0438\u0437 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 list \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.<\/p>\n<p>  \u041c\u044b \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bytes.Buffer. \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u043b\u044e\u0447 -gcflags &quot;-m -m&quot; \u043a\u043e\u043c\u0430\u043d\u0434\u044b go build. \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0443, \u0430 build \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043f\u043e\u0447\u0435\u043c\u0443.<\/p>\n<h2>\u041e\u0442\u0447\u0435\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430<\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043f\u0440\u043e\u0441\u0438\u043c \u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u0430\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043b\u044f escape analysis \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 10<\/p>\n<pre><code class=\"go\">$ go build -gcflags &quot;-m -m&quot;<\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 \u0432\u0441\u0435, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442 stream.go: 83, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 stream.go \u2014 \u044d\u0442\u043e \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0430 \u0441\u0442\u0440\u043e\u043a\u0430 83 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f bytes.buffer. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c 6 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 11<\/p>\n<pre><code class=\"go\">.\/stream.go:83: inlining call to bytes.NewBuffer func([]byte) *bytes.Buffer { return &amp;bytes.Buffer literal }  .\/stream.go:83: &amp;bytes.Buffer literal escapes to heap .\/stream.go:83:   from ~r0 (assign-pair) at .\/stream.go:83 .\/stream.go:83:   from input (assigned) at .\/stream.go:83 .\/stream.go:83:   from input (interface-converted) at .\/stream.go:93 .\/stream.go:83:   from input (passed to call[argument escapes]) at .\/stream.go:93<\/code><\/pre>\n<p>  \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 stream.go: 83.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 12<\/p>\n<pre><code class=\"go\">.\/stream.go:83: inlining call to bytes.NewBuffer func([]byte) *bytes.Buffer { return &amp;bytes.Buffer literal }<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bytes.Buffer \u043d\u0435 \u0438\u0441\u0447\u0435\u0437\u043b\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 bytes.NewBuffer \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b, \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u044b\u043b \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c.<\/p>\n<p>  \u0412\u043e\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u0434\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0434\u0435\u0442 \u0440\u0435\u0447\u044c:<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 13<\/p>\n<pre><code class=\"go\">83     input := bytes.NewBuffer(data)<\/code><\/pre>\n<p>  \u0418\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0440\u0435\u0448\u0438\u043b \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 bytes.NewBuffer, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u0439 \u043a\u043e\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u044d\u0442\u043e:<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 14<\/p>\n<pre><code class=\"go\">input := &amp;bytes.Buffer{buf: data}<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f algOne \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bytes.Buffer \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0418\u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437 \u0441\u0442\u0435\u043a\u043e\u0432\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0430 algOne? \u042d\u0442\u043e\u0442 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 5 \u0441\u0442\u0440\u043e\u043a\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0432 \u043e\u0442\u0447\u0435\u0442\u0435.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 15<\/p>\n<pre><code class=\"go\">.\/stream.go:83: &amp;bytes.Buffer literal escapes to heap .\/stream.go:83:   from ~r0 (assign-pair) at .\/stream.go:83 .\/stream.go:83:   from input (assigned) at .\/stream.go:83 .\/stream.go:83:   from input (interface-converted) at .\/stream.go:93 .\/stream.go:83:   from input (passed to call[argument escapes]) at .\/stream.go:93<\/code><\/pre>\n<p>  \u042d\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043d\u0430\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0431\u0435\u0433 \u0432 \u043a\u0443\u0447\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 93 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u043e\u0434\u0430. \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 input \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<h2>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b<\/h2>\n<p>  \u042f \u043d\u0435 \u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u0434\u0435\u043b\u0430\u043b \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443 93, \u0441\u0442\u0430\u043d\u0435\u0442 \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 16<\/p>\n<pre><code class=\"go\"> 93     if n, err := io.ReadFull(input, buf[:end]); err != nil {  94         output.Write(buf[:n])  95         return  96     }<\/code><\/pre>\n<p>  \u0412\u044b\u0437\u043e\u0432 io.ReadFull \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 io.ReadFull, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e input \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 17<\/p>\n<pre><code class=\"go\">type Reader interface {       Read(p []byte) (n int, err error) }  func ReadFull(r Reader, buf []byte) (n int, err error) {       return ReadAtLeast(r, buf, len(buf)) }<\/code><\/pre>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0430\u0434\u0440\u0435\u0441\u0430 bytes.Buffer \u0432\u043d\u0438\u0437 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Reader \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0431\u0435\u0433 (escape). \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0446\u0435\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432\u044b\u0441\u043e\u043a\u0430: \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0435\u044f\u0441\u043d\u043e, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043b\u0443\u0447\u0448\u0435, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0441\u043b\u0435\u0434\u0443\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0432 \u043c\u043e\u0435\u043c \u043a\u043e\u0434\u0435.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0433\u0434\u0430:<\/p>\n<ul>\n<li>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 API \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/li>\n<li>\u0423 API \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438.<\/li>\n<li>\u0411\u044b\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0447\u0430\u0441\u0442\u0438 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/li>\n<\/ul>\n<p>  \u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<ul>\n<li>\u0440\u0430\u0434\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/li>\n<li>\u0434\u043b\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/li>\n<li>\u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b.<\/li>\n<\/ul>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u0435\u0431\u044f, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u044d\u0442\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u043d\u0443\u0436\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f io.ReadFull? \u041e\u0442\u0432\u0435\u0442 \u2014 \u043d\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0438\u043f bytes.Buffer \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u043e\u0442\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 io, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 Read \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 input.<\/p>\n<p>  \u042d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 io, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u043e\u043a \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043f\u0443\u0441\u0442\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043f\u0430\u043a\u0435\u0442\u0430 io. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0443 \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 18<\/p>\n<pre><code class=\"go\"> 12 import (  13     &quot;bytes&quot;  14     &quot;fmt&quot;  15     _ &quot;io&quot;  16 )   80 func algOne(data []byte, find []byte, repl []byte, output *bytes.Buffer) {  81  82     \/\/ Use a bytes Buffer to provide a stream to process.  83     input := bytes.NewBuffer(data)  84  85     \/\/ The number of bytes we are looking for.  86     size := len(find)  87  88     \/\/ Declare the buffers we need to process the stream.  89     buf := make([]byte, size)  90     end := size - 1  91  92     \/\/ Read in an initial number of bytes we need to get started.  93     if n, err := input.Read(buf[:end]); err != nil || n &lt; end {  94         output.Write(buf[:n])  95         return  96     }  97  98     for {  99 100         \/\/ Read in one byte from the input stream. 101         if _, err := input.Read(buf[end:]); err != nil { 102 103             \/\/ Flush the reset of the bytes we have. 104             output.Write(buf[:end]) 105             return 106         } 107 108         \/\/ If we have a match, replace the bytes. 109         if bytes.Compare(buf, find) == 0 { 110             output.Write(repl) 111 112             \/\/ Read a new initial number of bytes. 113             if n, err := input.Read(buf[:end]); err != nil || n &lt; end { 114                 output.Write(buf[:n]) 115                 return 116             } 117 118             continue 119         } 120 121         \/\/ Write the front byte since it has been compared. 122         output.WriteByte(buf[0]) 123 124         \/\/ Slice that front byte out. 125         copy(buf, buf[1:]) 126     } 127 }<\/code><\/pre>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f bytes.Buffer \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 19<\/p>\n<pre><code class=\"go\">$ go test -run none -bench AlgorithmOne -benchtime 3s -benchmem -memprofile mem.out BenchmarkAlgorithmOne-8        2000000          1814 ns\/op         5 B\/op            1 allocs\/op<\/code><\/pre>\n<p>  \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0432\u0438\u0434\u0438\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 29%. \u0412\u0440\u0435\u043c\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u0441 2570 \u043d\u0441 \/ \u043e\u043f \u0434\u043e 1814 \u043d\u0441 \/ \u043e\u043f. \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0440\u0435\u0437\u0430 \u0434\u043b\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 buf. \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 20<\/p>\n<pre><code class=\"go\">$ go tool pprof -alloc_space memcpu.test mem.out Entering interactive mode (type &quot;help&quot; for commands) (pprof) list algOne Total: 7.50MB ROUTINE ======================== ...\/memcpu.BenchmarkAlgorithmOne in code\/go\/src\/...\/memcpu\/stream_test.go      11MB       11MB (flat, cum)   100% of Total         .          .     84:         .          .     85: \/\/ The number of bytes we are looking for.         .          .     86: size := len(find)         .          .     87:         .          .     88: \/\/ Declare the buffers we need to process the stream.      11MB       11MB     89: buf := make([]byte, size)         .          .     90: end := size - 1         .          .     91:         .          .     92: \/\/ Read in an initial number of bytes we need to get started.         .          .     93: if n, err := input.Read(buf[:end]); err != nil || n &lt; end {         .          .     94:       output.Write(buf[:n])<\/code><\/pre>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0441\u0442\u0430\u0432\u0448\u0430\u044f\u0441\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 89, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0440\u0435\u0437\u0430.<\/p>\n<h2>\u0421\u0442\u0435\u043a\u043e\u0432\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u044b<\/h2>\n<p>  \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0434\u043b\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0440\u0435\u0437\u0430 \u0434\u043b\u044f buf \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0431\u043e\u0440\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0438 -gcflags &quot;-m -m&quot; \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u043e\u0438\u0441\u043a stream.go: 89.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 21<\/p>\n<pre><code class=\"go\">$ go build -gcflags &quot;-m -m&quot; .\/stream.go:89: make([]byte, size) escapes to heap .\/stream.go:89:   from make([]byte, size) (too large for stack) at .\/stream.go:89<\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u0447\u0435\u0442\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u00ab\u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0434\u043b\u044f \u0441\u0442\u0435\u043a\u0430\u00bb. \u042d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0432\u043e\u0434\u0438\u0442 \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435. \u0414\u0435\u043b\u043e \u043d\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0443 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>  \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u044b \u0432 \u0441\u0442\u0435\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0437\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0435\u043a\u043e\u0432\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0443.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u044d\u0442\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u0445\u0430\u0440\u0434\u043a\u043e\u0434\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0440\u0435\u0437\u0430 \u0434\u043e 5 \u0438 \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 22<\/p>\n<pre><code class=\"go\">89     buf := make([]byte, 5)<\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 23<\/p>\n<pre><code class=\"go\">$ go test -run none -bench AlgorithmOne -benchtime 3s -benchmem BenchmarkAlgorithmOne-8        3000000          1720 ns\/op         0 B\/op            0 allocs\/op<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043e\u0442\u0447\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0443.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 24<\/p>\n<pre><code class=\"go\">$ go build -gcflags &quot;-m -m&quot; .\/stream.go:83: algOne &amp;bytes.Buffer literal does not escape .\/stream.go:89: algOne make([]byte, 5) does not escape<\/code><\/pre>\n<p>  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0445\u0430\u0440\u0434\u043a\u043e\u0434\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0440\u0435\u0437\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0436\u0438\u0442\u044c \u0441 1 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/p>\n<h2>\u0410\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>  \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435 \u043f\u0440\u0438\u0440\u043e\u0441\u0442\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435.<\/p>\n<p>  \u041b\u0438\u0441\u0442\u0438\u043d\u0433 25<\/p>\n<pre><code class=\"go\">Before any optimization BenchmarkAlgorithmOne-8        2000000          2570 ns\/op       117 B\/op            2 allocs\/op  Removing the bytes.Buffer allocation BenchmarkAlgorithmOne-8        2000000          1814 ns\/op         5 B\/op            1 allocs\/op  Removing the backing array allocation BenchmarkAlgorithmOne-8        3000000          1720 ns\/op         0 B\/op            0 allocs\/op<\/code><\/pre>\n<p>  \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 29% \u0437\u0430 \u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443\u0431\u0440\u0430\u043b\u0438 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044e bytes.Buffer \u0438 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u043d\u0430 ~ 33% \u043f\u043e\u0441\u043b\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439. \u0410\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u0430\u0434\u0430\u0442\u044c.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412 Go \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 escape analysis. \u041e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0441\u0442\u0435\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u043a\u0443\u0447\u0435. \u0412\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439, \u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>  \u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0433\u0430\u0434\u0430\u0442\u044c \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u0434 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0435\u0433\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438 \u043e\u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u0430. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u044f\u0437\u044b\u043a\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/511176\/\"> https:\/\/habr.com\/ru\/post\/511176\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/511176\/\">\n<h2>\u041f\u0440\u0435\u043b\u044e\u0434\u0438\u044f<\/h2>\n<p>  \u042d\u0442\u043e \u0442\u0440\u0435\u0442\u044c\u044f \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u0441\u0435\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0430\u0441\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0435 \u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439, \u0441\u0442\u0435\u043a\u043e\u0432, \u043a\u0443\u0447, escape analysis \u0438 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\/\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0432 Go. \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u0435\u0439:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/05\/language-mechanics-on-stacks-and-pointers.html\" rel=\"nofollow\">Language Mechanics On Stacks And Pointers<\/a> (<a href=\"https:\/\/habr.com\/ru\/post\/496846\">\u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/a>)<\/li>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/05\/language-mechanics-on-escape-analysis.html\" rel=\"nofollow\">Language Mechanics On Escape Analysis<\/a> (<a href=\"https:\/\/habr.com\/ru\/post\/497994\/\">\u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/a>)<\/li>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/06\/language-mechanics-on-memory-profiling.html\" rel=\"nofollow\">Language Mechanics On Memory Profiling<\/a><\/li>\n<li><a href=\"https:\/\/www.ardanlabs.com\/blog\/2017\/06\/design-philosophy-on-data-and-semantics.html\" rel=\"nofollow\">Design Philosophy On Data And Semantics<\/a><\/li>\n<\/ol>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u044d\u0442\u043e \u0432\u0438\u0434\u0435\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430: <br \/>  <a href=\"https:\/\/engineers.sg\/video\/go-concurrency-live-gophercon-sg-2017--1746\" rel=\"nofollow\">DGopherCon Singapore (2017) \u2014 Escape Analysis<\/a><\/p>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043e\u0431\u0443\u0447\u0438\u043b \u043e\u0441\u043d\u043e\u0432\u0430\u043c escape analysis, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u0435\u043a\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u042f \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0432\u0430\u043c \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u0443\u0447\u0443. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0441 \u044d\u0442\u0438\u043c \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-307015","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307015"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307015\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}