Garmin fēnix 5 Review


I’ve wanted a heart rate monitor for some time, mainly to improve my cardio performance and to track my progress as I go. One big thing for me is the wrist-based form factor because it gives you ambient recording, as well as not having to carry around a chest strap and all the awkwardness that entails.

I’ve done a lot of research into this over the past year and I’ve ruled out things like the FitBit (which only shows you HR for a few seconds when you press a button), and the ill-fated Pebble Kickstarter (I’m so disappointed they folded). Finally after a lot of reading, hand-wringing, and a very convenient 20% off sale at Rebel Sport, I apologised to my bank balance and bought the Garmin fēnix® 5.

Garmin fēnix models

Garmin’s fēnix line is the high end of the Garmin sports watch range, and is priced to suit. In Australian dollars you can pay $1k for the top of the line fēnix 5X, with the fēnix 5 and fēnix 5s retailing for$800. So these aren’t devices to consider lightly.

The main difference between the three is size:

 fēnix® 5Sfēnix® 5fēnix® 5X
Diameter42 mm47 mm51 mm
Thickness14.5 mm15.5 mm17.5 mm
Weight67 g85 g98 g
Battery life (smart mode)9 days14 days12 days
RRP (🇦🇺)$799$799$999
Garmin Fenix 5 prices in Australia circa 2017

There’s some smaller other differences, namely the “sapphire editions” of each watch give you a sapphire crystal display and wifi connectivity if you’re so inclined.

But more generally the 5S is intended to fit smaller wrists, and the 5X has more storage and comes with maps.

Garmin fēnix 5 comparison

The cool stuff

I’ve covered what the Garmin fēnix models are, but why would you buy one?

For me there are a few reasons:

First, it’s a really nice piece of design. This is something that’s going to last a long time rather than be replaced every year, so I want something that looks good and isn’t going to date terribly like a cheaper smartwatch might.

On a similar note, the hardware itself is truly excellent. I’m not going go into details when DC Rainmaker has done such a comprehensive review of the tech. If you’re considering this device and want all the benchmarks, definitely read that article because it’s what tipped me over the edge.

Perhaps most importantly it’s not an Android watch so it’s not going to lose access to updates, slow down, become a security risk or generally suck like OEM Android devices do. It’s an OS purpose-built by Garmin that does one thing well, and should mean the watch will live a long and prosperous life even after Garmin drops support for it.

Finally the Garmin ecosystem has really good Strava support which I use almost every day. Having this in a standalone device means on longer workouts I’m not sucking power from my phone, and can last some 24 hours without a charge — much longer than I can.


Initial impressions

I tried on each fēnix model at the shop before making my decision; the fēnix 5S didn’t even fit around my wrist, but the 5 sat snugly and looked good, so I anguished over the decision for another 20 minutes before finally taking it to the register.

The device itself is lovely. In the box it’s a carbon/polymer + stainless steel affair with a rubber band. You can get metal bands which I’m considering due to an unfortunate issue with sensitive skin, but the default combo looks great.

Pairing was simple, the app found the device before I’d even asked it to which was impressive. Once paired it immediately started sending notifications from my phone. I’m not a big fan of this feature and the next thing I did was turn notifications off for reasons of sanity and battery life. For me this is a fitness & tracking device, not a smartwatch.

The OS is fairly intuitive; it’s not touch based, but it has a very simple up/down/select/back navigation and all the features are nearby and easy to find. It’s also fairly standalone, so you could get away with using this without a phone if you wanted, however to sync to Garmin Connect and various other internet services you’ll need to bluetooth pair it.


Display in full sunlight
Display in ambient light with backlight
Display in litle light with no backlight
Display in little light with backlight

One thing that’s really stood out for me is the screen; not being a traditional LCD display, this one turns off the backlight and draws almost no power while still being completely legible. In fact, legibility is best in direct sunlight with no backlight, making this a really awesome exercise companion. I was super pleased to be able to start my bike ride today, switch to the heart rate mode, and check that easily throughout the trip.

As a result of that, the battery life should be measured in weeks, as opposed to the mere hours of the current generation of smartwatches.

Conclusion

It’s early days, but I’m pretty happy with this device. From a fitness tracker perspective it’s awesome, and I’m really optimistic about how this thing is going to fit into my fitness regime.

It’s not a smartwatch, and if you’re going into the market looking for that you may be disappointed, but it’s a really great purpose-built fitness tracker that also serves as a watch.


Update 2019

So this was an awesome watch, I really enjoyed using it. Problem was, after a while I noticed my skin was starting to itch and go weird where the watch was sitting.

After a few weeks of alternating wrists and trying to make things work, both arms a patch of messed up skin and I reluctantly decided to sell it on eBay. Guess I’ve got sensitive skin.

Still, good watch! Recommended!


Update 2022

Ever indecisive, I decided to grab a second-hand watch on eBay to give this one more try. It was cheap enough second-hand, and from the original article it’s still plenty usable because the software is fantastic!

This time instead of using it as an every day kind of affair, I plan to use it mainly for cycling and workout tracking to save the battery in my phone. So things worked out alright in the end anyway!

Proofer: an API Blueprint renderer


I'm a big fan of good documentation. It's hard to do, and doubly so with poor tools.

At work we've been using API Blueprint for documenting our systems, and while it's been serving us well, the tooling leaves me wanting more.

Some of the problems I have:

  1. Responsiveness: I don't mind a slow compilation step, but a lot of the tools struggle with large files, leaving a slow page render and no free RAM on my system
  2. Automation: I want to build my API docs from a GitHub repo and push them wherever. There are tools like Aglio that can do this, but the output is visually very dated and incredibly slow
  3. Readability: Apiary is beautiful but doesn't support automation super well, since it primarily wants to be an online editor. None of the third party tools come close in terms of features or general experience.

With that in mind, this weekend I figured I'd try my hand at generating some docs using Ractive (the virtual dom-like mustache templater) and Bootstrap 4.

Proofer (a frontend to Drafter)

The result of my work is a little project called Proofer (a frontend to Drafter) with the aim of letting developers quickly create and manage templates to render documentation.

It has two parts

  1. A backend renderer which renders an API Blueprint file into a JSON equivalent
  2. A frontend render which takes the JSON and outputs HTML

It uses the emscripten-compiled Drafter.js library rather than the full-fat C build, because npm packages with a compile step jangle all my pet peeves.

This also means that in the future we can implement client-side authoring and intelligent differential updates using Ractive (which as an aside is something that I'd like to see Apiary do too).

Sample render

Performance

So how does this implementation stack up?

It's a client-side rendered single page app which definitely satisfies the responsiveness criteria. Only the stuff you're interested in gets loaded into the DOM, and the content is only rendered as you navigate between categories. This is lightning fast on an initial page load.

Page render for a large API completes in under a second

You can see that the render of our large API Blueprint akes less than a second. There's a fair bit of JS parsing waste that could possibly be fixed with an async load, but this is not too bad considering our existing render takes a good twelve seconds thrashing around with jQuery UI before the page is loaded.

Our existing API docs SUCK

I always noticed, but never realised just how slow our existing docs had become.

(An amusing aside, the Apiary editor had crazy memory leaks and would chewing up gigabytes of RAM editing our documentation in Chrome before we moved authoring to GitHub.)

Other niceties

In terms of readability, this is wholly subjective. I don't think the layout is super amazing, but It's using Bootstrap 4 for styling which I think is a good base to work on, and it's something I'll continue to develop.

One of the killer features though, is the integration of Ace Editor for payload rendering. You can click “view in editor” on any JSON glorb to open it up in Ace where you can quickly search, edit, do code folding etc. For APIs returning large payloads, this is priceless because standard JSON rendered into the page is really hard to navigate.

Finally, in terms of automation this isn't quite there yet. While it has the command line app for the build step, I'd like to split out the components so others can easily build their own documentation. At the moment this is still tightly coupled, though won't be difficult to break up.

Conclusion

Interestingly, the easiest part about this project was the parsing since the heavy lifting had already been done by the good folks at Apiary.

The toughest part is styling the output to be both visually pleasing and useful, something that I'm planning to continue working on.

Ultimately the most important part is having the documentation in the first place. I've joked with my colleagues about quitting my day job to follow my passion of being a technical writer… but for now I'll stick to doing both.


You can fork the project on GitHub or see some preview output of a fictional API.

Follow @ashkyd

Reading List

I haven't posted here in a while so I figured I'd put up some links to things
I've been reading recently.

Android's emoji problem

Android has a myriad of problems, but one of the as-yet-to-be-solved ones is
that of emoji.

Other core parts of Android are broken out and updated out of band through the
Play Store, but emojis are still tied to Android release versions and OEMs just
aren't keeping up.

With numbers like that, it's no wonder so many apps are providing their own
custom emoji support these days.

As always my opinion is that if you want any hope of a decent Android
experience you need to use a Google branded device 😔

» Android's emoji problem

Doomsday prep for the super-rich

This is a fascinating look at doomsday preppers and what they're doing for the
impending collapse of civilisation.

“He was telling me we should buy land in New Zealand as a backup. He’s, like,
‘What’s the percentage chance that Trump is actually a fascist dictator? Maybe
it’s low, but the expected value of having an escape hatch is pretty high.’ ”

That little voice in the back of your head has never sounded more sensible.

» Doomsday prep for the super rich

The debate over punching white nationalist Richard Spencer in the face, explained

Look, I'm not going to say I didn't enjoy this entire fiasco, but this outlines
both sides of the argument.

Also, this tweet:

» The debate over punching white nationalist Richard Spencer in the face, explained

Speak, memory

“When her best friend died, she rebuilt him using artificial intelligence”. Hit
me right in the feels, with an obligatory Black Mirror reference.

Who’s your best friend?, she asked.

Don’t show your insecurities, came the reply.

It's an older story, but this has been at the forefront of my thoughts a lot
lately, that our digital detritus may one day keep us alive. Supplemental
thought: What makes up “me”?

Anyway, it's beautiful and I dare you not to get teary.

» Speak, memory

Isometric buildings in Inkscape


It's been a while since I've made a new building in Inkscape, but this weekend
I had a crack at a building I've been admiring for a while,
Manor Apartments
in Brisbane CBD.

I've been making these for a while. They're stylised vector-based
isometric
building tiles that can be used in some hypothetical game I might make one day.
The colours are specifically chosen from a palette that lets me

programmatically recolour them on the fly
.

I find getting the base sorted at the start is really useful. In most cases,
this just involves drawing a square or rectangle base and I have a template which
you can see in the image that lays out a standard block size of 256×128
pixels. This building is easy in that it's essentially a rectangle so I can get
away with minimal changes.

Next step is drawing windows, or other repetitive features. These can be cloned
so that they don't need to be re-drawn, and any subsequent changes only need
to be made to the original in order to flow through to the entire image. Usually
there's two copies of each feature with different shadows; one facing left and
another facing right.

This building is a little more tricky because it has the sweeping arches on the
ground floor, as well as various arched windows which are more difficult to draw
since they're not basic square shapes.

Once the ground floor is done, it's a step-by-step process to add floors until
we reach the roof. For the most part these can be duplicated from lower floors
or assets can be reused in different arrangements.

This building is fun because it has so much variety on the different levels. I
stylised or glossed over over a lot of the ornamental detail in the original
building because it doesn't fit with my existing style, but I like how it
adds a sort of plastic simplicity to the end result.

My plan with this building was to make it modular, so that I could repeat
variations of the first tile a few times to create the rest of the building.
This image shows two very similar tower pieces placed next to each other to
make a larger building. I've colourised it, and added a couple of other older
buildings to check the styles work together.

Finally, I've added and subtracted some floors, added a roof and placed a few
different sized blocks around to make a completely new building. No longer Manor
Apartments, but a series of blocks that can be configured numerous different
ways.

The end result are four separate tower pieces that can be combined or used
individually to create various large and small buildings. I think it worked
really well, and it's something I want to explore in future buildings.

Manor Apartments

Hexo, static site generator


For a while now I've been running a custom hybrid of Ghost and the static site generator I built early last year. While it was doing the job, it was a bit ugly on the backend and difficult to maintain so as a Christmas project I went looking for a replacement.

Hey Hexo!

After some cursory googling I found Hexo, which seems to satisfy all my fairly simple requirements:

  • node-based to make the most of the NPM ecosystem, and because I don't like Ruby dependencies.
  • Plain and simple, no weird tech or lock-in.

Hexo

Functionally Hexo is pretty similar to Jekyll and uses all the same terminology.

The directory layout is split between source for content and themes for layout. The latter can deal with CSS and Javascript preprocessing automatically, which I was initially cold on (small modules, yo!), but it grew on my when I realised the "hexo server" site preview tool was automatically recompiling CSS & JS as I was making changes.

It's fairly pluggable, and supports my favourite Markdown renderer Marked which does lovely things to Markdown.

Custom metadata

One of the things I'm a particular fan of with Hexo is the ability the put data (as either YAML or JSON) into the front-matter. This is awesome because it lets you make templates to do pretty much anything.

One example is my Projects page, which now consists of a paragraph of actual text, and a big glop of JSON representing each project. The template takes the JSON and renders the page as if by magic, and it's much nicer than trying to organise that stuff manually.

Hexo Homepage

Conclusion

Pretty happy with this one. I've been wanting to standardise on something decent, and this fits the bill nicely. There's a whole bunch of tools and the workflow is nice. The documentation is excellent and the process of getting from nothing to a functioning site is pretty straightforward.

I like it. If you're looking for a static site generator in the Node ecosystem, then definitely give this one a go.

Road Blocks & js13k

I've been looking forward to entering the js13k competition this year, because it's one of my favourite game jams.

TLDR: play Road Blocks (don't forget to like and share :P)

Set over a month-long period, the js13k challenge is to create a compelling game within 13 kilobytes. This doesn't sound like much, but you can do a lot with it if you get creative.

Last year I dreamed fairly small, with a space invaders clone set to polar coordinates. I had fun making it, but it wasn't especially playable and this year I wanted to do something completely different and come up with a mobile friendly touch-based game.

Road Blocks screenshot

The Concept

The concept had been rattling around in my head for a while. I've a very soft spot for city builders, and I love isometric art. While an outright city builder probably wouldn't be feasible, a subset thereof might just work.

My main inspiration was an old DOS/Windows game called Pipe Dream, in which you're given an infinite number of puzzle pieces and need to connect the start pipe to the edge of the map somewhere before the liquid spills out. Mash this concept up with the city building theme and you've got a basic connect-the-infrastructure sim.

When the theme of the jam came out as “reversed” I really struggled to find a way to align the concept with the theme, so I had to mix it up.

Ultimately I landed on the puzzle-style "arrange the pieces to fit" theme, in which you need to strategically destroy or reverse the order of the tiles as they come off the queue. It's a little less "world buildy" and a little more constrained, but I think the gameplay works, and it gives me the opportunity to expand the game with new puzzles in the future.

The Tech

The tech is also an idea that's been bouncing around in my head for a while. I've long been a fan of isometric art (pixel art as well as more recently isometric vector art and voxel art) so I wanted to do something in that style.

I had a play around in CodePen and came up with a crazy simple plan; draw everything in voxels. The algorithm to draw an isometric cube isn't all that difficult. You've got three visible sides, each side consisting of four lines and a fill colour. Turn that into a function and you can start making some cool stuff.

See the Pen HTML5 Canvas isometric cube demo by Ash Kyd (@AshKyd) on CodePen.

You can adjust the sliders on the example above to modify the cube.

Drawing voxel sprites

With the idea down, the next step was to draw a game world. There's a bunch of sites out there that have isometric code examples. I had Clint Bellanger's isometric math tab pinned in my browser for a good week, though in reality there were only two functions I really needed:

  • Convert isometric position to screen/pixel position
  • Convert screen/pixel position to isometric position

These two functions let me both draw isometric boxes to the appropriate location on the screen, and then detect where those boxes were stacked when the user interacted with them.

From there, the trick was to come up with sprites made from boxes. While it was possible to sort of work it out in your head, this was often a trial-and-error process, placing boxes and seeing where they land in the output.

See the Pen HTML5 Canvas isometric cube demo by Ash Kyd (@AshKyd) on CodePen.

In the above example you can see a road tile with three components, rendered from an array:

var sprite = [
  [-0.25,.9, 0, 0.1, 1, 0.25, '#aaaaaa'],
  [-0.25,.1, 0, .8, 1, 0.2, '#444444'],
  [-0.25,0, 0, 0.1, 1, 0.25, '#aaaaaa'],
];

Each item in the array corresponds to a coordinate. In this case the z, x, y coordinates, x width, y width and height.

In the end, my sprite list resulted in a bunch of arrays and functions that don't make a great deal of sense to the naked eye but render cute little box sprites in the game engine.

Putting it all together

With a bunch of sprites at my disposal, all that was left was to implement the game! Easy, right?

I actually took a week off specifically to work on Road Blocks, and I'm glad I did. Through the week I implemented the engine various features (some of which didn't make the final version) and tuning interactions.

Because I wanted this to be a first-class touch game, I implemented everything mobile first. This was a fantastic way to discover all the limitations of the platform at the get-go rather than having to refit a desktop game to mobile later on.

I also spent a lot of time user testing the game, be it in person or through analytics. Testing is a really important part of any gamedev process, and it was really enlightening to watch people playing my game for the first time. Many a puzzle or interaction was tuned based on feedback and watching people work out a level.

I also released my game via Twitter as a public beta to gather play statistics and weed out any errors that might crop up. I used Loggly to record a bunch of custom game stats and events, and the results were quite valuable in determining difficulty and how people were faring playing the game.

One particularly revealing fact was that most people were getting stuck on a particular level. Armed with feedback from testers and the hard facts of the analytics, I tweaked it to be not quite as difficult and pushed it from the middle of the campaign to the end to make it a sort of "final boss" level instead.

As a side note, one day I got distracted and came up with a data encoding scheme for level data which helped reduce the file size in the final zip.

Conclusions

I'm really pleased with the results this year. The game clocked in at just under 13 kilobytes and made efficient use of the space.

Some notes in hindsight:

  • Levels and sprites should probably use a binary data scheme to reduce file size and allow the use of Web Workers.
  • For some reason HTML5 canvas makes the CPU spin up like crazy. I'd like to get to the bottom of this sometime.
  • User testing is mandatory. When developing something in isolation you can get into a weird headspace and not notice the obvious stuff.
  • I had initially intended to have little cars animating along the roads, but ran out of space and couldn't think of how best to do this. I need to learn more about vectors in gamedev.

Ultimately, this year's js13k was a whole heap of fun and I'm really proud of my result. There's a bunch of awesome entries that you should check out, and you should consider entering next year.

Further reading

You can play Road Blocks on the js13k website. You can also check out:

jsfxr sequencer

I didn't go into this weekend with a project, but I woke up Saturday with an idea I couldn't get out of my head — I want to write a music sequencer with a really low footprint for use next month in the js13k game competition.

I've written about js13k before, and took part last year. This time around I want to be a bit more prepared, and I wanted to make a tool that would make it easier for the community to make cool stuff!

So this weekend I've been working on a bunch of different tools to make this project a reality.

Mini Sequencer

Mini sequencer is exactly that: a mini sequencer implementation that can play sounds at various times to form tunes.

This was my first mini project, as I was interested to see what the performance of web audio would be like; it's surprisingly good. That said, if I get time I'd like to look into replacing it with the Web Audio API, as it's a lot less hacky and should perform better.

jsfxr-editor

jsfxr is a little 8 bit synth which was implemented a few years ago for use in the js13k competition.

Since this is probably what most of my sounds are going to be implemented by, I wanted to be able to create new sounds from my sequencer. While there's a few sites out there (my favourite by Super Flash Bros) that let you adjust sliders and make new sounds, there's not actually an out-of-the-box tool you can use to plug into your own project.

So after a bit of reverse engineering of as3fxr (the original Flash version), now there is.

This actually took up a whole bunch of my time, and if I were a project manager I would have dropped this to focus on other stuff, but hindsight, right?

Fruity Timeline

I got to the end of the weekend and felt like I hadn't really ended up with much to show off.

The timeline was one of the big things I'd been putting off doing because it's slightly weird and I wasn't quite sure how to tackle it, so I went all-out and implemented a standalone component (depends on jQuery but probably doesn't need to).

I'm pretty proud of this one, it's styled reminiscent of the old Fruity Loops sequencer and just looks a bit retro.

The main event

So despite having made a million things this weekend, I haven't actually finished the project I set out to do. Right now I have:

  • Create & manage a library of instruments (with jsfxr editing built in)
  • A super rudimentary timeline (edit some JSON by hand and the music will update)
  • BPM adjustment.

Things I need to do from here:

  • Plug in the actual fruity timeline so you can edit your song visually.
  • Implement a "piano roll" feature so you can have different pitches of the same instrument.
  • Stop/play/seek functionality
  • Export your file
  • Load up proper audio files (mp3/wav/whatever) so you can play with those too.

It looks like there's a lot there left to do, but I think I'll be able to get a minimum viable product done with another weekend. I'm not sure if I want to publish the code yet since it's a massive pigsty, but I'll aim to get something out before next weekend is through.

Edit: Ended up getting something together Sunday night. Try it out.

Web workers – an overview

We recently had a talk about about service worker at BrisJS — the local Javasccript meetup — but I wanted to take a step back and talk a little more generally how workers all fit together.

You can view my original slides & interactive presentation on GitHub.

What’s a worker?

A worker is essentially a separate process in which you can run some Javascript code.

The thing about Javascript is that like most programming languages it’s single-threaded, which means when you’re executing code you can only do one thing at a time. We've got it fairly good with async tasks in Javascript land, with things like AJAX and upcoming ES6 promises, but even still if you've got a long-running task it’s going to lock up your thread until it’s done.

This doesn't sound so bad until you consider that the thread you're executing Javascript in also includes the thread that renders your page, which means your animation, scrolling, the whole shebang will stop working until your JS is done.

Thus separating your Javascript into a separate worker process can significantly improve performance on your site if you’re doing a lot of processing.

Quick description of workers

So should you just stick your code in a worker and hope for the best, right? Not quite.

A worker gives you a more Javascript-oriented environment than your standard script is used to. To start with, there's no window object, so things like window.onload don't do anything (the script in the worker starts firing once it's loaded, and doesn't need to wait for anything else). There's also no DOM or XML parsing, and you only get a subset of the APIs you’d have access to in a regular Javascript page.

This means that the code in your worker is essentially sandboxed from the regular goings on of your page, and you have to structure your app accordingly.

With such a restricted environment, it's easy to discredit workers, but there are several things a worker is good for:

  • Pretty good sandbox – makes you more mindful of your code, and helps you write good, testable modules.
  • Ideal for discrete tasks – Things that you can boil down to a standalone component are great for use in workers.
  • Longer running, CPU intensive tasks – These are where workers shine. If you're doing anything at all that might take longer than the 16.66 milliseconds/60 fps of your page draw, consider taking it out of the main thread for super performance gains & smooth animation/scrolling.

So this might include things like browser games or web apps with large amounts of data.

Types of worker

There’s three main types of worker:

  • Dedicated workers are the bread and butter worker, and work in almost all browsers. They’re really simple, you can fire them up in your page, do some processing, tear them down. Easy!
  • Shared workers are similar to dedicated workers, except you can fire one up and access it from anywhere else your entire origin. Multiple tabs and all. These aren't especially well supported, and in my opinion have been mostly superseded by:
  • Service workers! A relatively new type of worker with a longer lifecycle, which can run in the background even when your page is closed, and has a few extra APIs. They’re essentially designed to make the web more app-like.

Start up a worker

Starting up a worker looks a little something like this:

// index.html
var echoWorker = new Worker('echoworker.js');
echoWorker.onmessage = function(message){
    console.log('%cMessage from worker: ', 'color: darkred', message);
};
echoWorker.postMessage('Hello worker!');

In this example, we're firing up a worker by pointing to an external script echoworker.js and listening for any messages it might send us.

Then we're sending a hello world message to our new worker.

// echoworker.js
addEventListener('message', function(event) {
    console.log('%cMessage from parent: ', 'color: blue', event.data);
    postMessage(event.data);
}, false);

Inside the worker we can run any code we like. In this example we're simply listening for any messages our parent might send to us, and echoing them back once they've been received.

You can try this code on this page by opening up the console in the presentation and running echoWorker.postMessage('Hello worker!');.

Postmessage API

The postMessage API is the main way of communicating with a worker and has two parameters: message and transferList.

myWorker.postMessage([mixed] aMessage, [array] transferList);

In the initial spec, the message parameter only supported passing of strings, but modern browsers support structured clone which is a spec that’s similar to JSON.stringify except it supports a bunch more things, like blobs, files, regexes etc. This means that you can send a large number of data types through the message parameter, including objects.

One point to note is that passing messages using this API works differently due to the cross-process nature. While traditional Javsascript objects are passed by reference and exist only once in memory no matter how many times you pass them around, objects passed through postMessage are duplicated in order to exist in both processes. So if you're sending large amounts of data between workers, you may end up accruing a lot of duplicated memory that needs to be garbage collected.

To get around this, the transferlist parameter lets you transfer certain data types, rather than duplicating them. At the moment the only data types you can transfer are ArrayBuffers (binary data), but this covers a number of high-profile use cases including Canvas graphics and file handling.

The following example transfers the ArrayBuffer rather than duplicating it:

var myMessage = {
    command: 'doTheThing',
    data: someArrayBuffer
};
echoWorker.postMessage(myMessage, [someArrayBuffer]);

Worker sope

There's not a lot of API devoted to managing workers. Essentially you have:

  • Worker.terminate()
  • WorkerGlobalScope.close()
  • WorkerGlobalScope.importScripts()

Terminate lets you terminate a worker from the main script. Close lets you terminate a worker from the inside.

importScripts is the fun one, it's essentially the equivalent of putting a <script> tag into your HTML document, in that it blocks the page and loads the script at that point in time. Of course since we're in a worker it doesn't matter if we block the Javascript because it doesn't affect what's in the page, so this is useful for loading any dependencies you might need before your script runs.

My preference here is to simply bundle everything up with Browserify (because you get all the benefits of NPM and don't have to worry about the file management and extra requests that ensue) but you can just as easily use the native implementation.

Some gotchas

One of the biggest gotchas I've hit when using workers is scripts expecting window to exist. You've probably seen stuff like this around:

if(window.XMLHttpRequest){
    // do the magic
}

It's a handy shortcut to check if something exists, but it's a bit of an antipattern these days because often these functions may exist in another global scope. In Node you've got global and in workers you've got self, so in each of these environments your code is going to throw an error and break everything.

There's two ways you can solve this:

  • Either wrap the offending code in a closure:
    (function(window){ […] })(self);
  • or ensure window exists:
    self.window = self;

The first option is nicer because it's a less grotty-globally hack, but the second is by far the easiest and doesn't seem to cause any problems.

How fast are workers

Guillaume Cedric Marty did a bunch of benchmarks on some of their low end Firefox OS phones over at the Mozilla Hacks blog recently, so if you're interested in the details you can check that out..

The summary: firing up a new worker is the slowest part of the whole affair, everything else is blindingly fast.

Operation Cost
Initialisation ~40ms
postMessage latency ~0.5ms
Communication speed 45kB/ms

The take-out from this is that you should fire up only as many workers as you need, and reuse them for common tasks. You can do this by having all your tasks bundled into the one codebase, and then running one or more identical workers that you can share tasks across as required.

Another consideration in terms of performance is only firing up as many workers as will benefit your system. Considering your render thread is already taking up a process, you should consider firing up cores - 1 workers (or if your render thread won't be doing much, fire up a worker per core.)

You can get the number of cores in a system using the webkit-specific navigator.hardwareConcurrency or using one of the polyfills depending on your needs.

Actually writing an app with workers

So you're writing an app that will be using workers, one of the most important things to get right is the communication. postMessage is a super simple communication mmethod, so you'll probably want to build something on top to make this smoother.

  • My favourite thing to do is write a little async ‘do something’ api, so you can post commands and receive callbacks.
  • Something I've been playing with is running the whole model in a worker. This can be useful when dealing with lots of data & processing.
  • An existing library: there's a bunch of them. I like workerproxy because it gives you load balancing and some debugging for free, but I've found it can eat errors and make things difficult sometimes.

Further reading

My battery is about to run out, so I'll leave you with some more reading materials that you can go through to get you on your way:

The trials of moving house in a Telstra dominated area

My lease was running out and I was vaguely looking at apartment prices in my area when I saw it: my dream place.

My dream place turns out to be a converted loft upstairs from an organic cafe that’s never open and adjacent to an overgrown empty lot. From the outside it’s terrifying, but the inside is all natural light, high ceilings with rafters and tacky faux-wood linoleum. It was my first choice last time I moved house (and was unfortunately off the market before I got it) but this time damnit, it was going to be mine.

My new place! there's boxes everywhere and plants needing a home

So I inspected it, submitted an application, and moved in over the weekend. Couldn’t be easier!

Then I tried to get the Internet on.

Telstra Velocity Fibre Smart Community haha wait, oh dear

For those who aren’t in the know, in 2012/13 Telstra replaced the ageing copper network from the South Brisbane exchange with fibre to the premises. The caveat being that it’s still wholly owned by Telstra and has nothing whatsoever to do with the NBN.

It’s known by various names, “South Brisbane Fibre” being the preeminent one, but Telstra also calls it “Telstra Velocity” or a “smart community” just to make things confusing.

The idea is nice, but as far as the consumer is concerned it would have been better if the rotting copper was left in the ground. Since getting their “smart” on Telstra jacked up wholesale prices, started demanding exorbitant monthly line rental fees, and throttled the network to copper-comparable speeds anyway.

Since the government prevents other parties rolling out networks that compete with the NBN and there’s none of the checks and balances the ADSL network enjoys, this is an outright Telstra monopoly and they seem to be making the most of it.

Getting connected in South Brisbane

At my previous place in South Brisbane it took $300 and almost two months chasing iiNet to get online.

At my new place I figured I’d ditch iiNet because they were so useless and go straight with Telstra because surely being the operator of the network they’d have a better idea of what they’re doing.

Turns out not.

  1. On my first attempt to sign-up I was told that ADSL isn’t available at my current address and that’s that.
  2. Feeling annoyed I attempted to sign up online, where I was told that I can absolutely 100% get cable Internet and everything’s fine. Makes sense, fibre is a cable right? I signed up, submitted my order, all good.
  3. Several days later I get a call to let me know that actually I can’t get cable (HFC) in at my apartment: I can only get fibre, and do I want to continue the signup?
    As a consumer, I don’t care about this stuff, I just want to get on the Internet so of course I want to continue. The order languishes for the next couple of weeks while I’m out of town.
  4. When I call up to chase the order I get bumped through three different teams (sales, cable and finally “smart communities”). The guy doesn’t outright say they’ve lost my order, but takes all of my details again before offering me a vastly more expensive plan on a 24 month contract at which point I give him a super polite ultimatum before hanging up and punching some nearby kittens.

The plan on offer was somewhere in the vicinity of $130/month before line rental (another $30 which they don’t tell you until the price goes up at the end). This brought it to over $150/month for the most basic access to the ‘net which is totally unreasonable and I have no idea how they can get away with it.

This month’s internet bill just hit $470 not including what it’s costing to get my landline connected. When was that NBN happening again?

— Ash Kyd (@AshKyd) May 29, 2015

My next port of call was TPG who either refuse to service the South Brisbane area as a result of Telstra’s ridiculous monopoly, or just didn’t know what they were doing. I don’t blame them either way, getting online here has been one of the most frustrating things I’ve had to do as an adult and if I were a service provider I would avoid dealing with Telstra wherever possible.

Finally I called Internode who knew exactly what was going on and generally didn’t completely suck. The downside is their South Brisbane plans run between $150-200 per month for a paltry 250 GB. At this point I just don’t care because I’ve already burnt through more than double that figure this month in mobile broadband and need to get online, but it’s an extraordinary figure and I’m having trouble justifying it.

So what’s going wrong?

It’s easy to blame Telstra for being a lumbering, incompetent monopolist but how did this happen?

In both cases my address hasn’t been in whatever database they use to look things up, and both times it’s caused holdups from “we can’t find you in the system” and “you can’t get Internet” to “we accidentally disconnected your landlord instead, lol soz”.

Surely having just finished updating the network in 2013 they would have all this information? Apparently they don’t keep this around, as even my current apartment which was only disconnected the previous month is completely missing from the system.

Meanwhile I still don’t have Internet at my new place and they seem completely unwilling to help.

— Ash Kyd (@AshKyd) May 29, 2015

Further, both times I’ve had to have technicians come out to poke around to work out what’s going on. The first time took a full four hours to suss out the building connectivity, including everything from calling the helpdesk to shining lasers down the fibre to work out which cable needed to be plugged in at the basement. These visits cost $300 a pop and it’s a total rort.

That it’s the 21st century and you can’t light up an apartment within five minutes by filling in an online form is boggling, and I just don’t understand how so much human intervention is required to get the data flowing over a damn fibre network.

The clincher I think is the all-’round lack of knowledge not just within Telstra where the teams are all siloed and don’t know what they don’t know, but also within the resellers of which only Internode seem to have trained their staff. Essentially, nobody knows what’s going on.

And the NBN?

Yeah, the NBN is pretty much dead. There’s no fibre coming, no hundred megabit, let alone gigabit networking. The policy’s there in name, but the political will certainly doesn’t seem to be.

New developments (like hopefully my new new place) will get NBN fibre, but existing premises aren’t so lucky. As I understand it the current plan is to buy back Telstra’s corroded copper network and roll out HFC and VDSL tech as far as it will go. South Brisbane on the other hand, is likely stuck with Telstra for the rest of time since it’s unlikely the government will separate them or buy up the fibre network any time soon.

Meanwhile the alternatives aren’t many. I’ve currently got a $140/month, 50 GB LTE service from Vodafone which is a reasonably attractive offer by South Brisbane standards but nowhere near girthy enough for my needs. The best Telstra and Optus can offer are 10 GB and 12 GB respectively which is laughable. Beyond that there’s no alternative but to capitulate and give Telstra your firstborn.

Three weeks later

I’m still waiting to be connected. I’ve spent nearly half a grand on Internet (and that’s before the laying anything down for a wired service) and I’m seemingly no closer to having my fibre box light up than I was when I started.

I’m kinda starting to think think I should just quit tech and become a barista.

Sony Xperia Z3 Compact Review

Oh dear. That's the first thought that crossed my mind when I turned this thing on. Oh dear, what have I gotten myself into.

The hardware's fairly pleasant. The mix of glass and plastic feels a bit like an upmarket Nexus 4. It's about the same size as that generation of phones, but the screen is big, at 70.6% screen-to-body ratio (compared to the Nexus 4's 68% or the iPhone 6's 66). It's also exceptionally thin and light; you can tell it's a flagship product.

But damn, the software. The instant I turned it on I was greeted by a custom setup wizard thing. Sony has seen fit to come up with their own software for the setup, and that's probably fine. It asks me to sign in to some Sony stuff and whatever, I can skip it.

Then the phone boots and it's like we're running Android 2 again. Everything's pokey icons and stupid animated wallpapers that look like nothing anyone would ever classify as good design. The launcher's customised, the drawer's customised, the settings are customised to the point that I can't even find where to set up my Google account.