Online marketplace eBay has revealed how it boosted performance of a demanding web app by 50x using WebAssembly.
SEE: Tips for building a successful career as a software engineer (free PDF) (TechRepublic)
By compiling code to WebAssembly,can build apps that deliver consistently high-performance in the web browser, similar to that offered by apps running natively.
eBay was keen to exploit that performance for a web version of its barcode scanner, a feature it offers in its Android and iOS apps to allow sellers to scan items they are auctioning.
"WebAssembly was different. It has tremendous potential, we just did not have the right use case. Well, that changed recently," said the eBay software engineering team in an eBay blog post.
One of the advantages of WebAssembly (Wasm) is that it offers code portability for a variety of languages, allowing developers to take code they've written for other platforms and compile to WebAssembly so it can run in major web browsers.
Consequently, eBay was able to take the existing version of its barcode scanner written in C++ and compile that to Wasm using Emscripten, adopting the Docker and Node.js-based approach outlined here.
The problem was the Wasm-based scanner was still unable to detect barcodes in 40% of cases.
The team were initially puzzled why the same C++ code that worked in about 100% of cases when compiled to native code for Android and iOS apps was failing when compiled to Wasm to run in the browser. It eventually emerged that these native apps were able to bypass problems with image quality using platform-specific APIs that allowed for autofocus and other features.
Only by running all three side-by-side in separate web worker threads, and having each attempt to read the barcode, was the scanner web app able to handle close to 100% of barcodes.
"To our surprise, with three threads racing against each other, the success rate was indeed close to 100%. This again was totally unexpected," write the team.
The final web-based barcode scanner also proved to be a success with customers during an A/B test, leading to a 30% increase in eBay users who completed the process of listing an item for auction on the site.
"Technology evolves at a very rapid pace. Every day we hear new things getting launched. But only a few make a difference to customers, and WebAssembly is one of them," the team said.
- Six in-demand programming languages: getting started (free PDF) (TechRepublic)
- Telephone interview cheat sheet: Software developer (Tech Pro Research)
- Programming languages: Your best options (ZDNet)
- Want to learn programming? This startup pays you cryptocurrency to study Python (ZDNet)
- 10 popular programming languages developers should learn in 2019 (TechRepublic)
- Get our latest coverage about programming languages (TechRepublic on Flipboard)