Reply
Thread Tools
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#141
Originally Posted by zimon View Post
I know there has been lots of work to tackle this heap memory fragmentation problem in Firefox, but what it means in fact you have to eventually write some kind of CG with C++.
If you mean GC as Garbage collector, no, a memory pool
would help. There is less memory fragmentation with a GC,
just because a GC manages a bigger memory pool.
Originally Posted by zimon View Post
If one would use Java from the start, you already would have CG and re-JIT with current desktop modern VMs.
It is a common mistake to think, a programing language with
a GC avoids memory leaks.
 
Posts: 1,341 | Thanked: 708 times | Joined on Feb 2010
#142
Originally Posted by nicolai View Post
Hm,

The page you quoted is about memory fregmantation when many
windows (or pages) are opended even right after start. So,

if all is good again, even if you restart your session with all tabs,
I don't believe this memory fragmentation was the reason.
No. The page is about memory fragmentation when many windows, tabs, or pages are opened and closed right after the start.

Loading a bunch of windows and closing them and clearing my caches
Also read this:
So.. What does this mean?

Well, it means that any allocations >4k are going at the end because we can’t really fit them anywhere earlier. This is bad for a variety of reasons including performance. It makes it very difficult for us to get big chunks of contiguous memory to give back to the OS. This makes us look big!
Originally Posted by attila77 View Post
And back to square one. Comparing a language to a platform. Why do you say only Java can have a VM type solution or that a Java VM solution is the best VM solution ?
I did not say that. In fact there was no word "Java" in a section you quoted. I've tried to use "interpreted language" as often as I have remembered, because there is a point. Another point is, comparing to Python, static typing makes optimization much more easier than Python's dynamic typing when sometimes type changes and type casting cannot be known until runtime.

Now that is plain FUD. The memory leaks that are caused by pointer assignments are easily detectable with the proper tools, and if you use things like Qt, handled automatically (say hello to guarded and scoped/reference counting pointers). *Logic* based leaks (i.e. not getting rid of objects you don't really need) is a different matter and no choice of language will help you there.

BTW So now Chrome and Opera are slow and leaky, too ?
I haven't looked (yet) how Qt tries to tackle the heap memory fragmentation problem ("guarded and scoped/reference counting pointers"), but in the compilers I've made and studied for couple of different type of languages I do not think you can factually get rid of pointers any way more efficiently than for example Java does it in VM.

When you have an alive pointer pointing to some memory area of the heap, you cannot move that memory segment in a different place if you cannot know all the places in the code where that segment maybe is pointed or accessed. As I said, you can try to avoid using direct pointers and arrays everywhere in C++ code, but then in fact you are building a similar kind of clever GC Java for example has (and Python will have if it doesn't already).
And if you cannot move the allocated memory segment, or segments around it, you cannot de-fragmentate nor can you reorganize alive object to fit better locally to reduce cache misses.

Pointers suck in OOP-code what it comes to optimizing for space and speed and power consumption.

Last edited by zimon; 2011-02-10 at 13:36. Reason: GC, no CG
 
Posts: 1,341 | Thanked: 708 times | Joined on Feb 2010
#143
Originally Posted by nicolai View Post
If you mean GC as Garbage collector, no, a memory pool
would help. There is less memory fragmentation with a GC,
just because a GC manages a bigger memory pool.

It is a common mistake to think, a programing language with
a GC avoids memory leaks.
Modern GCs will make memory de-fragmentatiion and re-organization to fit better to CPU cache based on information collected in runtime. I do not know if latest Java VMs already does that, but they will.

Keeping cache miss count low even when program has been running long time and there is lots of different life-span dynamic objects, is becoming more and more important when latency between cache access and main memory access seems to increase all the time. Active heap-memory management can make this happen. It can effectively be done only if direct pointers are either forbidden (Java,Python) or avoided manually (not that convenient way).

Last edited by zimon; 2011-02-10 at 14:35. Reason: GC, no CG (again)
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#144
Originally Posted by zimon View Post
No. The page is about memory fragmentation when many windows, tabs, or pages are opened and closed right after the start.
Yes, but your point was, firefox suffers under memory fragmentation,
after it is running for days. But the blog post is about memory
fragmentation which happens right after start.
Originally Posted by zimon View Post
I haven't looked (yet) how Qt tries to tackle the heap memory fragmentation problem
("guarded and scoped/reference counting pointers"),
I don't see what referencecounting has to do
with preventing memory fragmentation.
Memory fragmentation happens when you allocate a huge number
of small objects.
Originally Posted by zimon View Post
As I said, you can try to avoid using direct pointers and arrays everywhere in C++ code, but then in fact you are building a similar kind of clever CG Java for example has (and Python will have if it doesn't already).
What do you mean with CG?

Nicolai
 
Posts: 1,341 | Thanked: 708 times | Joined on Feb 2010
#145
Originally Posted by nicolai View Post
What do you mean with CG?
I mean both Garbage Collector (so GC, sorry, typo) but also heap memory management. VM can know also in runtime which objects are used temporaly (session runtime-wise) close each-others and use that information when allocating new objects OR, in the future if not already, re-organize objects to keep cache misses low. C-compiler cannot know all this information because it is not available in compile-time.
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#146
@zimon
You are right a GC (and the heap memory management) can help
to prevent memory fragmentation. And to do this java is more
appropiate than C++. But my point was:
Originally Posted by zimon View Post
One of the reasons why Firefox slows down and "leaks" memory, which you notice after several days heavy use, is because it has been coded with C++ and it cannot use this extra running time information for optimization.
Memory fragmentation and memory leaks are different things.
And the blog post you quoted is about memory fragmentation
and not about "slows down and leaks memory after several days".
 
Posts: 1,341 | Thanked: 708 times | Joined on Feb 2010
#147
Originally Posted by nicolai View Post
@zimon
You are right a GC (and the heap memory management) can help
to prevent memory fragmentation. And to do this java is more
appropiate than C++. But my point was:

Memory fragmentation and memory leaks are different things.
And the blog post you quoted is about memory fragmentation
and not about "slows down and leaks memory after several days".
I had purposely the word "leaks" quoted. The real memory leaks are always bugs, which can be fixed also with C++, but memory fragmentation factually also seems like memory leaking, when after few days my Firefox starts swapping and gets slow although it would have the same session, tabs, pages open which were in the start.

It doesn't have to be several days to notice the problem if you just open and close lots of pages like the guy in the link did. And if you use heap memory printing like he does, you notice the problem before it affects the speed of the application.
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#148
Originally Posted by zimon View Post
It doesn't have to be several days to notice the problem if you just open and close lots of pages like the guy in the link did. And if you use heap memory printing like he does, you notice the problem before it affects the speed of the application.
You're still trying to find faults in specific (historical) implementations and then pin it to C++ as whole, past present and future. The Firefox article is from 2007, so probably Firefox 2.x. Starting with 3.x, Firefox uses jedmalloc, which solves that problem (so whatever you think is making your firefox slow today, it's not memory fragmentation - more likely Flash or some other junk ).

http://en.wikipedia.org/wiki/Malloc#...D.27s_jemalloc
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 
Posts: 1,341 | Thanked: 708 times | Joined on Feb 2010
#149
Originally Posted by attila77 View Post
You're still trying to find faults in specific (historical) implementations and then pin it to C++ as whole, past present and future. The Firefox article is from 2007, so probably Firefox 2.x. Starting with 3.x, Firefox uses jedmalloc, which solves that problem (so whatever you think is making your firefox slow today, it's not memory fragmentation - more likely Flash or some other junk ).
I think you are wrong. Saying it starts "swapping after few days" was somewhat overrated from me, but eventually it would start swapping also if I wouldn't restart. Also the situation has improved alot with time and with new Firefox major versions. But still Firefox memory consumption increases over time. If just this memory consumption would be the problem, I probably would re-start only when it starts swapping, but I can see the slowing down effect before that, and I think that is because fragmentation. (My laptop is relatively slow 1.8 GHz Turion)
Maybe I should just prove it with memory prints rather than claim in many posts by telling what, why and when.

What ever *malloc one uses, it doesn't fix heap memory fragmentation, it just slows the phenomena. Also you need to make a compromise whether to organize large and small objects in different regions, or organize temporary close objects together to reduce cache misses and increase locality; but then taking a greater risk with fragmentation if you cannot re-organize alive objects later and de-fragmentate.

The pointers in C code will always be a problem. There is numerous studies done to make better garbage collectors and memory managements, but pointers are always the problem. It is not a accident modern programming languages do not use pointers but only references.
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#150
Originally Posted by zimon View Post
I think you are wrong. Saying it starts "swapping after few days" was somewhat overrated from me, but eventually it would start swapping also if I wouldn't restart.
The point was that memory management is not part of the C++ specification so trying to find drawbacks there is just mudslinging. The bottom line being that we should avoid accusations of a certain behaviour and trying to set up wishful cause-effect relations just so that our favorite tech comes up top. As I said previously, a lot of Java people think about C++ as this awkward C bolt-on from the '80s, and C++ people think of Java as this academic bloatware. Well, dears coders and codettes, it's 2011 and neither is true.

The pointers in C code will always be a problem. There is numerous studies done to make better garbage collectors and memory managements, but pointers are always the problem. It is not a accident modern programming languages do not use pointers but only references.
This is the out-of-thin-air generalization that makes makes even your good points look bad. D has pointers. C# has pointers. Hell, even Google's brand spanking new Go language has pointers.
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 
Reply

Tags
bada rox, dalvik, future, java haters, meego, meego?fail, nokia, sandbox sucks


 
Forum Jump


All times are GMT. The time now is 16:30.