BiteofanApple Archive About Code Twitter
by Brian Schrader

Software performance in an ASM.js world

Posted on Mon, 16 Nov 2015 at 10:03 AM

There's been a lot of talk recently about using Javascript as the assembly language of the web, and tools like ASM.js allow developers to write code in any language they want and compile it, instead of to a native binary, into a subset of Javascript that can be run very efficiently in the browser. In fact, in testing Mozilla and Unreal were able to cross compile a few modern video games in to Javascript from C and the games played at half native speed! Frankly, that's amazing.

The Benefits of PyPy.js and ASM.js

If you've ever seen Gary Bernhart's talk, The Birth and Death of Javascript then you've seen this kind of thing before. One really cool project involving ASM.js is PyPy.js by Ryan Kelly which aims to be a fully compliant PyPy implementation running in the browser. One of the big issues with compiling a language to Javascript has always been how to make it fast, but during his PyCon 2015 talk Ryan demonstrated that although the PyPy.js version was indeed 10x slower than the native PyPy interpreter, it was over 1.2x faster than the native CPython interpreter which is the version of Python that most of us are actually using. While that may be a testament to just how good the PyPy interpreter and JIT compiler are, it does have some interesting implications for Python on the web.

<script type="text/python" src=""></script>

Ryan has gone on to say that, in his opinion, one of the major issues with using his PyPy.js in real world cases is that in order to begin running your code in Python on the web, each page has to download the PyPy.js interpreter, and it's not a small download. Currently, he says that the interpreter weighs in around 5MB when compressed. Once it's loaded however, the browser can cache the interpreter locally and avoid that cost in the future. To me, initial startup time is not really the big issue though, and while it's true that 5MB is a crazy big file to be transmitting over the web, most sites already force users to download that much data in ad tracking code alone.

What's the problem then?

An example of web site memory usage

In my mind, the issues facing developers using this new toolchain are not initial file downloads or startup time costs. These are one-time costs if developers leverage the new HTML 5 caching APIs like AppCaching and LocalStorage. Users are already accustomed to "Installing" software and moving that process to the web is something I'm confident designers and developers can do well. My concern has far more to do with runtime performance, specifically memory usage. In a world where most sites running lots of Javascript already use hundreds of megabytes, full ports of the PyPy interpreter on top of fully fledged applications are just going to make performance worse.

Web applications are immense resource hogs. What typically takes kilobytes of memory in a native application takes megabytes on the web. Frankly, that kind of usage is pretty unacceptable as is, and bolting an interpreter on top of that will only make the problem worse.

What's the solution?

Looking at the history of programming languages and performance, you could make the argument that this is just the next step. You could, for example, argue that the jump from native code to interpreted languages like Python had a similar cost in speed and performance, and I'd grant you that point. It certainly could be that the web is the single most important and viable development platform and that the performance costs will be worth it.

The jump to using the web as the virtual machine in which we run the software of tomorrow should be one we take with caution. The speed penalties aren't large, and I'm happy that that's true, but with most desktop users still having less than 6GB of memory and mobile users teetering around a third of that, developers will have to be careful not to try too much at once. Games can allocate gigabytes of memory and get away with it, but when a user's entire application suite is in the cloud, memory will be, as it almost always has been, a precious resource.

Ad tracking company using audio to identify users

Posted on Thu, 12 Nov 2015 at 02:30 PM

SteamFeed Admin:

It works like this: on the desktop side, SilverPush drops a cookie along with playing an inaudible audio, using speakers as audio beacons. The inaudible code is received and recognized on the mobile device by the software development kit that’s on the phone. This creates an immediate and accurate association between the desktop cookie and mobile device.

That's absolutely brilliant... and completely terrifying. It's just another example of what ad tracking companies will do given the technology.

Even more re: software and engineering

Posted on Mon, 09 Nov 2015 at 01:11 PM

Dr. Drang:

...the difference between hacking and software engineering is like the difference between carpentry and structural engineering. The carpenter takes lumber and nails it together in a way that seems right, while the structural engineer sizes and spaces the lumber using a rational approach based on the applied loads and the strength of the material...

But there’s a place for carpentry. If you’re building a shed in your backyard, there’s no need for a structural engineer. The rules of thumb of carpentry—which can be shown to have rational bases, even though the carpenter may not know them—are perfectly adequate to build a strong and durable shed. The trick is to know when you need structural engineering and when you can get by with carpentry.

Ian Bogost

The term is probably a shortening of “software engineer,” but its use betrays a secret: “Engineer” is an aspirational title in software development. Traditional engineers are regulated, certified, and subject to apprenticeship and continuing education. Engineering claims an explicit responsibility to public safety and reliability, even if it doesn’t always deliver.

The title “engineer” is cheapened by the tech industry...

The traditional disciplines of engineering—civil, mechanical, aerospace, chemical, electrical, environmental—are civic professions as much as technical ones. Engineers orchestrate the erection of bridges and buildings; they design vehicles and heavy machinery; they invent and realize the energy systems that drive this equipment; and they contrive methods for connecting all of these systems together...

It’s no accident that the most truly engineered of software-engineering projects extend well beyond the computer. Autonomous-vehicle design offers the most obvious contemporary example. Autonomous vehicles share the roads with human-driven cars, pedestrians, and bicyclists. Those roads are managed, maintained, and regulated. Engineering addresses complex, large-scale systems...

Other engineering disciplines are subject to certification and licensure...

Licensing processes vary by state, but Professional Engineers generally need to hold a 4-year degree from an accredited program in their discipline, pass one or more exams, and possess 4 or more years of professional experience under the supervision of a licensed engineer. Not all working engineers are or need to be Professional Engineers, but... to claim that one is an “engineer” in a formal context, licensure is usually required...

Engineers bear a burden to the public, and their specific expertise as designers and builders of bridges or buildings—or software—emanates from that responsibility.

These two posts sum up my feelings pretty well.

Why I'm switching back to iTunes

Posted on Mon, 12 Oct 2015 at 02:55 PM

Last week I decided to leave Spotify. I've been using the service for almost 2 years now, and overall I've really liked it. Their selection is great, their ability to stream audio over even the slowest connection is constantly impressive, and while the app's UI isn't perfect, it has gotten much better. As I said, I've really liked having Spotify, so why am I leaving?

Cancelling spotify

Like another service that I used to pay for but just cancelled, Spotify hasn't sat well with me over the last few months. It's hard to explain why, but I guess I feel apprehensive about Spotify being in control of how and where I listen to music in ways I haven't been before. An example of my frustration happened last week when I was trying to AirPlay some music from the Spotify app on my iPhone to my media center running OSMC. When I went looking in the AirPlay settings for a destination, my media center showed up, but it wasn't playing. Originally I thought it might be a bug between OSMC's AirPlay implementation and iOS 9, but when I tried streaming from the music app it worked fine. It also worked fine from iTunes on my Mac, but not from Spotify. This was extremely frustrating at the time, and it helped me reconcile the feelings that I'd been having toward Spotify in the recent months. Spotify is a great service, but like all proprietary services, it gets to decide how/why/where you can use it's material. This wasn't the first time I'd felt stuck because of Spotify's imposed limitations, it was just the last straw. I decided to resurrect my old music library, give iTunes a new icon, purchase the music I wanted outright, and cancel Spotify. 1

Getting a new icon

Now I know that iTunes is proprietary software with it's own set of limitations and hurdles, but the music I've purchased from it is mine. I have access to the raw audio files, and I can convert, burn, and AirPlay them anywhere I want. As long as it is technically possible to AirPlay to a device it should work, and that's becoming more and more important to me.

iTunes is not a great piece of software; it's overcrowded with features, and begging for a redesign and simplification, but with it's latest release it has gotten better. Once I cleaned out my old music library and basically started from scratch, I've really enjoyed using it, and with iCloud music library, I get the my-music-is-always-on-whatever-device-I'm-using benefit of a streaming service. Although I now have to go back and purchase my favorite albums again, overall I'm happy with my decision.

1. Another reason I've wanted to switch away from Spotify that is less relevant to this discussion is that since I don't usually listen to a new album every month, the cost of paying for a streaming service monthly is a little hard to justify.

Disable "shake to find cursor" in El Capitan

Posted on Mon, 12 Oct 2015 at 11:35 AM

I've been using Mac OX 10.10 El Capitan for a few days now, and it's been fairly solid for me. I've encountered some minor bugs, but overall it's a solid point-oh release.

One new feature that I'm not too fond of, however, is the new "shake to find your cursor" thing. I really don't know why it bugs me, but it does. So I went looking for a way to disable it.

The solution is pretty simple. Run the following command in Terminal, and reboot your machine.

defaults write ~/Library/Preferences/.GlobalPreferences CGDisableCursorLocationMagnification -bool YES

Original Post →


Subscribe to the RSS Feed. Check out my code on GitHub
Creative Commons License
BiteofanApple is licensed under a Creative Commons Attribution 4.0 International License.