Am Sun, 30 Jun 2013 22:55:26 +0200 schrieb "Gabi" <[email protected]>:
> I wonder why is that.. Why would deleting 1 million objects in > C++ (using std::shared_ptr for example) have to be slower than > the garbage collection freeing a big chunk of million objects all > at once. I have no numbers, but I think especially when you have complex graph structures linked with pointers, the GC needs a while to follow all the links and mark the referenced objects as still in use. And this will be done every now and then when you allocate N new objects. > I mean, it would probably block the main thread but the > avg rate of deleting objects shouldn't differ from manually doing > so right ? So the main issue would be unpredictable pauses > (what's a typical delay to expect from cleaning 1000000 objects?) > of the main thread and not avg performance I think.. The current implementation is a stop-the-world GC. It freezes all threads known to the runtime. (Excluding threads created with the native API and not registered with the runtime.) > Any other tips to get high performance besides the GC issue? From the top of my head: o Mark classes or single methods final when you can, as bearophile pointed out. (shaves off a few % in object heavy code) o See if you can use structs instead of classes, they don't have virtual methods and are simpler to allocate/return on the stack. o When working with strings, be aware that foreach iterates them by byte, whereas Phobos - in an attempt to do the right thing - iterates them by dchar (UTF-32 code point), which means a UTF-8 decoding process. o Some of Phobos is very fast, some is very slow. If you care much about performance evaluate different approaches before jumping to conclusions. As an example of the two last points combined, take finding a '\0' in a string (compiled with DMD): algorithm.countUntil: 355213 per second std.string.indexOf : 33121530 per second (~100x faster) Am Sun, 30 Jun 2013 19:53:05 -0700 schrieb Jonathan M Davis <[email protected]>: > On Monday, July 01, 2013 04:37:43 Mehrdad wrote: > > On Sunday, 30 June 2013 at 20:49:28 UTC, Peter Alexander wrote: > > > sometimes faster > > > > Would love an example that demonstrates it! > > Anything involving taking a lot of substrings is likely to be faster in D > thanks to slices (which is one of the main reasons that Tango's xml parser is > so lightning fast). I think he referred to the DMD backend being faster than GDC/LDC sometimes, no ? -- Marco
