To Optimize or Not To Optimize

corey602Developing an on-demand platform that must deliver speed, scalability and stability requires a lot of thinking about performance. While working on Bungee Connect, I’ve done enough code optimizations, tweaks, hacks, anything really to squeeze more performance to know that I need to pay attention to the details up front. Not to poke the “don’t optimize until it’s done” beehive, but I’ve learned enough to know that there are some things you can learn from experience and you don’t have to wait for the performance guys to laugh at your code.

Have you ever debugged a crash where a null pointer was being dereferenced and when you tracked down the individual responsible their defense was that checking for null would slow down the system?  Have you ever found someone that wrote their own atoi function because they swore that the standard c runtime’s implementation was bad?

If you read my previous post you’ll know that I’ve been playing with the V8 JavaScript engine by Google.  I’ve enjoyed learning a new system and gleaning tricks from other programmers that you don’t get from reading a book or taking a class. But something has been gnawing on my mind for the last little while and that is how fast or slow is the bridge between the v8 engine and a c++ application that embeds it.  I wondered whether or not a developer should be worried about the performance of this bridge or if they should forget about performance for now and just start turning the crank on features. So I wrote a little performance test to see how long different areas of the V8 integration into an application take. By the way, the Google engineers that wrote this system are very solid in terms of coding standards, efficiency and readability.

These benchmarks aren’t the most scientific in nature but they do give me something to start kicking around.  Here’s the JavaScript test that I wrote and embedded into my test:

var count = 0;

function timed_dispatch() {
count += 1;
}

start = new Date();

// Test 1
for (i = 0; i < 1000000; i++) {
count += 1;
}

// get the time and print the results
end = new Date();
print(end - start);

// reset the counter and the start timer
count = 0;
start = new Date();

// Test 2
for (i = 0; i < 1000000; i++) {
timed_dispatch();
}

end = new Date();
print(end - start);

// Setup for Test 3
timed_obj = new TimedCPPDispatch();
start = new Date();

// Test 3
for (i = 0; i < 1000000; i++) {
timed_obj.empty();
}

end = new Date();
print(end - start);”);

The first for loop measures how long it takes V8 to do some simple arithmetic on a variable.  I started with 10,000 iterations but the numbers were too small so I bumped it up to 1,000,000.  The output of the first print statement was 16ms.  Pretty quick.

The second for loop looks at how long it takes to do a method dispatch that increments the same number.  Adding the overhead of the function call took the time up 4ms for a grande total of 20ms.

The last for loop uses a C++ class that I created that has a function called empty.  This function literally does nothing except for return.  What I’m looking for is how long the act of dispatching a method from the javascript to the c++ application takes.  It took a total of 1500ms or 1.5 seconds to call 1,000,000 times.

Obviously, if you can avoid crossing the boundaries between your application and the V8 engine you will be saving some overhead.  Two orders of magnitude difference is nothing to sneeze at.  However, 1.5 us (microseconds) per function call is not bad for an embedded vm.  And, I don’t expect anybody to be doing a million of those. On top of that, once you cross the boundary you’re still running in c++ code, which isn’t too shabby with performance either.  If you have some complicated c++ algorithm that you are calling then a 1.5 us boundary becomes noise and is not an issue.  So, the old adage of not optimizing too soon would appear to still hold a lot of water in this argument and I should hold off on looking to outsmart myself before that’s really necessary.  I should probably be looking to add features to my application rather than trying to figure out a priori where my code might be slowing down.

If you’re interested in checking out V8’s performance numbers for running straight JavaScript head on over to http://code.google.com/apis/v8/run.html or download the V8 engine and run them on your machine.

Comments

Basecamp API for Bungee Connect from Bear454

The illustrious BCDN member Bear454 has contributed a Basecamp API for Bungee Connect. Bear454 outlines how you can use this api in your own project and promises to maintain it until a better one is contributed. Go check it out.basecamplogo-small.png

Brad

Comments

October System Update

The October system update for Bungee Connect went live on October 21.

For a more thorough list of this release’s new features, enhancements and bug fixes, review the Preview Announcement from September 26.

A few of the new features are worthy of a quick how-to video, so read on.

No More Pages in AppProjects
We simplified the AppProject container by eliminating the need for Pages. Any AppProjects that existed prior to the update will still have whatever pages they had before, but be sure to update your AppProjects before trying to update any existing deployed applications.

Here’s a short video to explain more.

“Publish” Tab Replaces “Staging” Tab
The new Publish tab makes it easier to manage your posts, deployments, and shares, especially when you have multiple solutions in various DesignGroups.

Here’s a short video to show you how.

Custom FavIcon Support
The much-requested support for specifying a FavIcons has finally arrived. Now when users bookmark your Bungee-powered application, they’ll see the icon of your choice.

Here’s a brief video to show how to implement a FavIcon.

Again, there is a whole lot more in this release, so check out the Preview Announcement from September 26.

Ted Haeger
Director, Bungee Connect Developer Network

Comments

BCDN Update, October 2008

This month’s newsletter was sent to all BCDN developers on Wednesday, October 8, 2008.

Since sending the email, there has been one modification to the original newsletter’s information. The new release of Bungee Connect will happen on Monday, October 13, not today. (I forgot about a cardinal rule of new releases, as set by BCDN members: never do a system update on a Friday. My bad!)

Hey, everyone:

It’s been a while since the last Bungee Connect Developer Network update, and we have been cooking up some great stuff for you. Let’s get to it. Read the rest of this entry »

Comments

Connecting C++ To Javascript Via Google’s V8

I’ve been playing around with Google’s V8 JavaScript engine. One of the really cool things about V8 is that it was built to be embedded into a C++ application. Here at Bungee Labs I’ve been writing the infrastructure for our bungee connect platform for some time now. One thing that I’m always interested in is speed and V8 is very fast. I ran the benchmarks that Google posted in my browser (Firefox 3.03), and then I ran them using the new V8 engine. The new engine is faster by an order of magnitude. Read the rest of this entry »

Comments

At Long Last: The Learn Tab v1.0

The Core Curriculum in the Bungee Connect Learn tab is finally complete, online and available.

Said one BCDN Developer (who goes by the handle “olympyx”):

I think the combination of text overview, video, and use of the platform is a great way to learn the platform. Read the rest of this entry »

Comments

October BCDN Preview Now Available

The next version of Bungee Connect is now available in preview to BCDN developers. As usual, the BCDN Preview will be online for two weeks before it rolls to production. Access it at https://preview.bungeeconnect.com.

The Preview once again has a recent snapshot of your solutions, but remember: the Preview release is for testing purposes. Any changes you make to your code will not be carried to production when the roll-up happens.

Of course, if you run into any issues, please leave a comment right here to let us know about them. Read the rest of this entry »

Comments (1)

Bungee Boys in New York City

Brad Hintze and I will be in New York City this week for Web 2.0 Expo. Along with us are our CTO Dave Mitchell, and CEO Martin Plaehn. If you’d like to get together with any of us, please drop us a note, and we hope to see you in New York.

Comments

Manage MySQL with Bungee SQL Admin

Bungee SQL Admin is a rich Internet application that enables Web 2.0 companies to rapidly manage MySQL & PostgreSQL database systems.

  • No install
  • No registration
  • No cost

Click here to launch. Read the rest of this entry »

Comments (1)

Bungee Boys at AWS Event in Salt Lake City

The Amazon Web Services crew are back on the road with their AWS Startup Tour, and Brad Hintze and I will be joining them tomorrow in Salt Lake City.

I’ll make a brief presentation around 3:30-ish, speaking about Bungee Connect and how Bungee Labs use Amazon Web Services. So if you’re in the area, please swing by to give Brad and me a hello.

Comments

« Previous entries