-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: memmove sometimes faster than memclrNoHeapPointers #23306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you sure that the escape analysis is working as you expect? Since the |
Here's a benchmark of the underlying memory copying/clearing primitives (you'll need to put this in its own package directory, along with an empty .s file to workaround #23311):
On my laptop, the relative performance seems very sensitive to the exact value of K. For example, at K=6e5, I get:
But at K=1e7, I get:
|
Probably unrelated, but this reminds me of 4k aliasing: https://lemire.me/blog/2018/01/04/dont-make-it-appear-like-you-are-reading-your-own-recent-writes/ |
For original benchmark memmove and memclr use different strategies. Memmove switches to non-temporal movs, while memclr uses regular movs. Changing non-temporal mov threshould in memmove to match memclr makes append faster:
However, for memmove tests from runtime switching to regular movs makes benchmark slower for larger sizes:
|
It looks this problem has been solved in Go Toolchain 1.15. |
Sorry, I mean |
Memory allocation using
make([]int, K)
is surprisingly slow compared toappend(nil, ...)
, even thoughappend
does strictly more work, such as copying.While reporting this issue, I initially used an older runtime from December 18 in which the effect was much stronger: 10x-20x slowdown. But that seems to have been fixed.
Curiously, this issue is the exact opposite of the problem reported in #14718 (now closed).
The text was updated successfully, but these errors were encountered: