[josm-dev] Jumbo Patch

Gabriel Ebner ge at gabrielebner.at
Mon Dec 17 22:53:24 GMT 2007


On Mon, Dec 17, 2007 at 11:22:54PM +0100, Petr Nejedly wrote:
> Frederik Ramm napsal(a):
> > On the other hand, if we re-write anyway, then we might just ditch
> > Java altogether and do it in C++, or maybe simply use Merkaator as a
> > start (don't know how well it is designed on the inside but it is a
> > fast C++ app that compiles easily on Win, Mac and Linux which is
> > probably enough for us). If people are really concerned about memory
> > usage and such (as in "you can't keep a list of ways with every node
> > as even the empty list will consume 80 bytes") there's just no beating
> > good old C++.
> 
> Really? Oh come on, you need to know your libraries, regardless of the language.
> Smallest possible growing list implementation would consume 32B (for single-slot,
> but still with the possibility of growing transparently) - one object with two
> fields and an object array.

I think we can get this down to 24 bytes (2 words for the VM[1], one to the
head element) by using a singly-linked list and representing nil as null.

[1] Are there any recent/accurate informations on the object layout of Sun's
VM?  The best I've found is this:
http://java.sun.com/developer/technicalArticles/Networking/HotSpot/
But it's almost 10 years old.

> inline one of them into the other data structure (Node in this case) thus saving
> one object header, but the fields will still be there. And in both cases, you can
> take the path of reused field and 4B/singleslot for typical case. At least as long
> as RTTI works for you in your C++ implementation.

You don't even need RTTI as you don't usually pass around lists as pointers of
unknown type.

I think the biggest saving in moving to C++ would come from being able to use
non-reference composite types.  Say we have this code now:

  public class Node {
    public Coordinate coord;
  }

  public class Coordinate {
    public double lat, lon;
  }

A Node instance takes 56 bytes now: 24 bytes for Node, 32 bytes for
Coordinate.

By not using a reference type we could save 24 bytes here (one pointer + one
header).

  Gabriel.




More information about the josm-dev mailing list