Windows multi-threading performance issues on multi-core systems only
dsimcha
dsimcha at yahoo.com
Tue Dec 15 09:23:01 PST 2009
== Quote from Dan (dsstruthers at yahoo.com)'s article
> My code does do considerable array appending, and I see exactly the same issue
as dsimcha points out above. I would expect it is GC related, but why for
multiple cores only, I cannot fathom.
> Thanks for the repro, dsimcha! My code snippet would not have been as
straight-forward.
Two reasons:
1. When GC info is queried, the last query is cached for (relatively) efficient
array appending. However, this cache is not thread-local. Therefore, if you're
appending to arrays in two different threads simultaneously, they'll both keep
evicting each other's cached GC info, causing it to have to be looked up again and
again.
2. Every array append requires a lock acquisition. This is much more expensive
if there's contention.
Bottom line: Array appending in multithreaded code is **horribly** broken and I'm
glad it's being brought to people's attention. For a temporary fix, pre-allocate
or use std.array.Appender.
More information about the Digitalmars-d
mailing list