News for hackers. Stuff that matters.
Re:Why are most browsers developed in C++? by specialist on Wednesday July 31, 2013 @01:52PM (#6135553)
you're not going to have a similar memory footprint with any kind of GC'd language

Cost of GC doesn't bother me.

Java's basic overhead for all data structures does.

Class String is a mistake. Better to have string scalars compiled down to char[], avoiding the class wrapper.

Massive overuse of HashMaps by most frameworks is huge drag too. Using typed collections (vs generics) like Trove helps quite a bit.

Our study group had a really good session on optimizing memory usage. Sorry, I can't quickly find the slidedeck we used. I used jamm to profile various strategies. Super fun.

I recently saw something in the newsfeed about JVM and optimal memory usage. Bit packing, word boundaries, ordering, etc. (It's more low level than I typically work, so I didn't bookmark it, sorry.)

Re:Why are most browsers developed in C++? by eropple on Wednesday July 31, 2013 @02:03PM (#6135643)
> Cost of GC doesn't bother me.

I generally work on the JVM and I do enjoy it, but if you're looking for rock-solid 60fps-all-day-every-day, the cost of GC without question should bother you a great deal.

I would never implement a browser in a managed language and I would do everything in my power to avoid gating rendering on the completion of execution of its scripting system for similar reasons.

Re:Why are most browsers developed in C++? by rossjudson on Wednesday July 31, 2013 @03:57PM (#6136446)
JVM != GC, although it is one of the best implementations out there.

Rock-solid FPS doesn't preclude GC. What it requires is a separate rendering layer that isn't subject to any GC pauses (or a game-like rendering loop that's always on time). The managed code manipulates the declarative level of the animations, and the low level handles the frame-by-frame details.

On relatively small heap sizes (under a GB) GC on recent PC hardware usually fits into the equivalent of a single frame -- under 30 milliseconds. Concurrent collectors would rarely need anything more than that, and wouldn't stop the world in any case.

The question here is, can you build a stable high performance rendering system on the JVM? If not, what would you have to change to be able to do that?

Correctly constructed you wouldn't have to change much. And JMonkeyEngine shows you can do a lot with what's there right now. There are some excellent discussions on its site on the topic of GC.

Re:Why are most browsers developed in C++? by eropple on Thursday August 01, 2013 @12:09PM (#6141274)
> Rock-solid FPS doesn't preclude GC. What it requires is a separate rendering layer that isn't subject to any GC pauses (or a game-like rendering loop that's always on time). The managed code manipulates the declarative level of the animations, and the low level handles the frame-by-frame details.

I don't think this is true. It's considerably more than rendering--it's reactivity. You need to handle audio streaming without pause, be able to process and dispatch input events seamlessly as well (I don't even know how you'd do this), so on and so forth. You'll essentially need to pull everything except actor logic out of the Java layer. Even some of that will be latency-constrained.

If anything, I think Unity is on the right path here: embed a sufficiently optimized virtual machine inside an engine that does all the hard work. But Unity still suffers from serious perf issues with nontrivial scenes. Like I said in another reply to you, object pooling is still heavily used in Unity because of the costs of object creation and destruction.

> On relatively small heap sizes (under a GB) GC on recent PC hardware usually fits into the equivalent of a single frame -- under 30 milliseconds. Concurrent collectors would rarely need anything more than that, and wouldn't stop the world in any case.

Sure, but that's too slow. The human eye can easily, easily, detect a dropped frame. Concurrent collectors (you mean Azul and friends?) are a possibility but we'd need a portable one that's freely licensed. If you've got one in your back pocket...gimme. =)

> The question here is, can you build a stable high performance rendering system on the JVM? If not, what would you have to change to be able to do that?

This is a tricky question. My instant reaction--"you can't"--feels right for the current state of the JVM. I do think something like Azul or another fully concurrent collector helps. But even then the JVM just has its limitations. Like, you're going to blow up your cache iterating a list of whatever your "GLbuffer" analogues are, unless you decompose all your objects. In most games way more of your code ends up being engine code than game logic code and so you're kind of hosing the main reason to use the JVM: a mostly-clean object-based system.

At that point, I'd just write C++ and embed a scripting language. (Recurring theme!)

> And JMonkeyEngine shows you can do a lot with what's there right now.

JMonkeyEngine is actually a major reason why I'm not using the JVM--if they can't get it good enough, I sure won't, right? IMO, you don't get enough from using the JVM (unless that's all you know, which'd just be sort of a shame) to make up for its limited platform reach and its perf issues. What you can do with it, right now, relative to just sucking it up and writing some C++ (and I do mean "sucking it up", I hate writing C++), just isn't enough.

Re:Why are most browsers developed in C++? by specialist on Friday August 02, 2013 @04:01PM (#6149319)
Thank you for the follow up(s).

No contest on your position regarding high fps and using a GC language like Java. I definitely don't have your experiences.

I equate VRML browsers with HTML browsers. General purpose, casual use, low cost of content production, etc. Just like with an HTML browser, even if you can make a fast twitch game with VRML, you probably shouldn't, for so many reasons.

My project was a virtual world construction kit based on a modular toy system. Think LegoCAD. At the time, VRML was ideal.

Re:Why are most browsers developed in C++? by eropple on Friday August 02, 2013 @11:44PM (#6151019)
If you said that HTML browsers should be that, I'd totally agree with you, but (unfortunately, IMO) they're not. They're app platforms now, and so performance becomes really critical. Like, stuttering animations make users mad at the browser, not at the (possibly stupid) code within it.

My last project was a now-defunct deformable-terrain world game[1], based on voxel fields and surface nets. We were running into problems with Lua's GC just on our actors, nothing else in the world. With the amount of data we were forced to push around, I can pretty confidently say that an all-managed environment would have killed us (because we tried it first in C# and it did).

[1] - An early video, before the team broke up: http://static.largerussiangames.com/voxels/videos/rigidbodie...