Freitag, 14. Mai 2010

Non-serialized heap is slow in Vista / 7

I've recently noticed that a Windows heap which is created with the flag HEAP_NO_SERIALIZE is very slow under Windows 7. There's not much information on the Web about this behaviour, and certainly no official information from Microsoft. It seems the problem also exists on Vista.

For a background: that flag is normally used to make the heap faster if one can be sure that only one single thread will ever access it at each point of time (either because there is only one thread accessing it anyway or because there is external synchronization for that heap anyway). In that case, synchronization inside the heap can be ommitted.

Most applications do not create their own heaps, but use those created by an underlying framework, e.g. the C++ runtime. The Microsoft CRT does not use that flag in its multi-threaded implementation (of course), and since Visual Studio 7, there is no single-threaded CRT any more anyway. But there are old applications built by Visual Studio 6 which may use the non-serialized heap. There are also special heap managers commercially sold which promise to boost application performance with special allocators, and these often use one allocator per thread and may also use one heap per thread underneath. And finally, there are some applications which do create their own heaps for memory management and / or performance reasons.

All these applications will become (at first inexplicably) slower when they run unchanged on Vista or Windows 7. Seems quite a bug to me. Speculation is that it comes from the decision to use the low-fragmentation heap by default on these operation systems. After all, that heap can't be used if the non-serialized heap is used. The reasons for that elude me, too ... perhaps MS just didn't think the non-serialized heap necessary any more; which would also explain why they didn't notice or didn't care about it getting slow.

Bottom line: HEAP_NO_SERIALIZE must not be used for an application which shall run on Vista and / or Windows 7. And because almost nobody delivers different binaries for XP / Vista / 7 / whatever follows, this precludes the use of the flag for years to come, possibly forever. Non-serialized heaps are dead.

0 Kommentare:

Kommentar veröffentlichen

Abonnieren Kommentare zum Post [Atom]

<< Startseite