4 ms·
> Game developers, take note: to ensure a 16ms frame time (required to achieve 60 frames per second), your application must make zero allocations, because a sin
by TheLoneWolfling 12y ago
> Game developers, take note: to ensure a 16ms frame time (required to achieve 60 frames per second), your application must make zero allocations, because a single young generation collection will eat up most of the frame time.
And this is why GC isn't the be-all and end-all solution to memory management.
(As as for people that are screaming "pauseless GC" - it has throughput issues [generally due to fine grained locking / other synchronization], and also often has a performance hit on your main thread [due to locking or read barriers, generally])
Now, if someone combined a pauseless GC with proper cleanup (i.e. skipping GC altogether) of variables where the compiler could determine when they can be thrown away, matters would be different. (So, in other words, the compiler inserts `malloc` (or whatever) calls, and ensures that every variable created is either `free`d exactly once after it becomes unreachable or is added to the set tracked by the GC (or is a constant - especially pertinent with strings). With (hidden) local variables to track control flow when different branches cause different allocations.)
- potench 12y agoI'm not sure I understand how to make zero allocations? Does this mean you create your variables outside of a requestAnimationFrame (rAF) and update their values inside the rAF?
- TheLoneWolfling 12y agoThat's what it means, yep. Making object pools, etc. This can be harder than it sounds, to put it mildly. In other words, completely subverting the GC altogether.
- angersock 12y agoObject pools for vectors are damned useful...both Xith3D and Ardor3D in Java had free pools for their vector classes, and using those significantly impacted memory usage and frame delays.
- aikah 12y agoSo basically one needs to re-implement smart pointers in Javascript, right ? What are the alternative to js style GC,for a language that wouldnt want to the developper to use manual memory allocation.I've heard about ARC.Are there other known architectures?
- TheLoneWolfling 12y agoAs I said: a pauseless GC with a smart language implementation would be fine. ARC can work, but either requires programmers to prevent loops or needs a GC regardless. Object pools at the language level would be an alternative. (I.e. every object is allocated in a "pool", including pools. When a pool falls out of scope the entire pool is "freed". You can copy objects between pools as necessary.)
- aikah 12y agothanks for your input.
- Dewie 12y ago> Object pools at the language level would be an alternative. (I.e. every object is allocated in a "pool", including pools. When a pool falls out of scope the entire pool is "freed". You can copy objects between pools as necessary.) This might be called "memory regions" in the literature, or at least the work on using this memory management scheme in an ML (ML Kit).
- nostrademons 12y agoAlso related to arenas - the main difference is that an arena is a block region of memory from which different-sized objects are allocated, while a pool is a collection of same-sized objects. Both are pretty common techniques in C, C++, and Ada, and pools are common in high-performance Java.
- Skinney 12y agoOr just a smart language implementation. Go makes it easier to avoid heap allocation, and thus GC, since it allows you to specify if a structure resides on the heap or stack.
- pjmlp 12y ago> And this is why GC isn't the be-all and end-all solution to memory management. At least a GC knows where your memory blocks are and doesn't double free them. > Now, if someone combined a pauseless GC with proper cleanup (i.e. skipping GC altogether) of variables where the compiler could determine when they can be thrown away, Have you ever looked into ParaSail, Rust, ATS?
- TheLoneWolfling 12y ago> At least a GC knows where your memory blocks are and doesn't double free them. Wrong. Counterexample: https://mail-archives.apache.org/mod_mbox/subversion-users/201307.mbox/%3CCAJC6wRu0xHZMKgvkTDNV4qXmvQv9WCArks6mXh+inEoChL23+w@mail.gmail.com%3E https://mail-archives.apache.org/mod_mbox/subversion-users/2... (Obtained by a quick search of "garbage collector double-free bug" - there are many others out there) > Have you ever looked into ParaSail, Rust, ATS? ParaSail and Rust don't have a GC, period, AFAIK. ATS is too strict for my liking. (I want a programming language that will refuse to compile if it can find a "counterexample" that will assert, but will compile something (with a warning and inserted runtime checks unless explicitly marked otherwise) even if it cannot prove something is correct.)
- pjmlp 12y ago> Wrong..... I don't touch Perl since 2004. Back then it used reference counting, not a GC. Second, the post reads like a problem in the C code. > ParaSail and Rust don't have a GC, period, AFAIK. ATS is too strict for my liking. I was replying about GC alternatives for automatic memory management.
- TheLoneWolfling 12y ago> the post reads like a problem in the C code. Exactly. All GC does is push down the code that can cause problems like double-frees into the language implementation. It doesn't magically make problems like double-free bugs impossible, like so many people say. > I was replying about GC alternatives for automatic memory management. Then why did you respond to and quote something that was talking about something entirely different?
- bostik 12y agoBy far the best write-up about mobile app development and the true cost of GC has been in [0]. It's a very long read but well worth it. If you took just one rule of thumb from it, let it be this: if you want speed with garbage collected languages, be sure to use at most 1/6 of the overall system memory. 0: http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/ http://sealedabstract.com/rants/why-mobile-web-apps-are-slow...
- Skinney 12y ago> Now, if someone combined a pauseless GC with proper cleanup (i.e. skipping GC altogether) of variables where the compiler could determine when they can be thrown away, matters would be different. (So, in other words, the compiler inserts `malloc` (or whatever) calls, and ensures that every variable created is either `free`d exactly once after it becomes unreachable or is added to the set tracked by the GC (or is a constant - especially pertinent with strings). With (hidden) local variables to track control flow when different branches cause different allocations.) Freeing is not an issue, you don't pay for garbage in a proper GC, as the GC only scans living objects, and never frees. The problem is allocation, as a scan is triggered when a certain number of bytes has been allocated. Go allows you to skip allocating on the heap (thus the GC), since you can define what is allocated on the stack or heap. You potentially could do as you propose, by inserting "free" at certain points where you could prove the variable was safe to throw away. Free would basically just then say "you can now postpone allocation, you have more free memory". But this has it's own drawbacks. For one you a minimal amount more to do (calling 'free'), but more importantly you will increase time spent in allocation objects, because you have to scan the heap for available space instead of just bumping a pointer. The most important thing is allowing the programmer a way to avoid the managed heap, which Go does, and C# to some degree does through structs.