Developers
Portable Native Client (PNaCl)
How I Learned to Stop Compiling and Love the Translator
David Sehr
Tech lead, Native Client
Molly Mackinlay
Product Manager, Native Client
It’s a new web
We aren’t in the 90’s anymore...
The web in 1995
The web today
Google+Photos
We now expect native features in the web
Native
Web
Developers are expected to develop cross-platform
Native Code in the Web – a History
1995
ActiveX
NPAPI
Native Code in the Web – a History
Java
Flash
Silverlight
1995
Native Code in the Web – a History
1995
2008
Native Code in the Web – a History
Security issues by plugin type*
*symantec
Native Code in the Web – a History
1995
ActiveX
Java
Flash
2008
Emscripten
2013
NPAPI
Silverlight
Native Code in the Web – a History
1995
ActiveX
Java
Flash
2008
Emscripten
2013
NPAPI
Silverlight
Why Bring Native Code to the Web?
Better performance
Increased developer options
Wins of Native Code in the Web
1995
ActiveX
Java
Flash
2008
Emscripten
2013
NPAPI
Silverlight
Native Client
Portable Native Client
gonacl.com
Developer Options
Our Solution: PNaCl
PNaCl is...
Native Code
Security
Performance
Platform
Independence
Access to Native: PPAPI
TCP/UDP
gonacl.com
Security
my_untrusted_code.nexe
Browser data
Browser APIs
OS APIs
X
gonacl.com
Platform Independence
ARM
x86
...
...
gonacl.com
Deploying to other browsers with pepper.js
app.cpp
Pepper API
Browser
Deploying to other browsers with pepper.js
app.cpp
Pepper API
Browser
PNaCl
app.pexe
Chrome
Pepper API
Deploying to other browsers with pepper.js
Emscripten
app.cpp
app.js
Pepper API
pepper.js
Browser
PNaCl
Other Browser
app.pexe
Chrome
Pepper API
Performance
| % of native | ratio to native* |
x86-32 | 90% | 1.11 |
x86-64 | 81% | 1.23 |
ARM (Chromebook) | 93%+ | 1.07 |
*via SPEC2k
lower is better
gonacl.com
Under the Hood of a PNaCl App
Building a PNaCl Application
C++ Source Code
pnacl-clang
.pexe
.nmf file (manifest)
<embed name="nacl_module"
id="airmech"
src="airmech.nmf"
type="application/x-pnacl" />
HTML
gonacl.com
Running a PNaCl Application
<embed name="nacl_module"
id="airmech"
src="airmech.nmf"
type="application/x-pnacl" />
HTML
embed
starts
translation
PNaCl Translator
airmech.pexe
airmech.com
air_mech_x86_64.nexe
Running a PNaCl Application
Native Client Sandbox
validator
air_mech_x86_64.nexe
?
Browser data
Browser APIs
OS APIs
gonacl.com
Running a PNaCl Application
Native Client Sandbox
validator
air_mech_x86_64.nexe
Browser data
Browser APIs
OS APIs
gonacl.com
Running a PNaCl Application
Chrome Sandbox
Chrome Sandbox
Native Client Sandbox
NaCl Runtime
air_mech_x86_64.nexe
gonacl.com
Running a PNaCl Application
Chrome Sandbox
Chrome Sandbox
Native Client Sandbox
air_mech_x86_64.nexe
NaCl Runtime
PPAPI
Browser data
Browser APIs
gonacl.com
Where are we and what’s next?
Google+Photos
“it’s virtually impossible to build great photo apps that can rival the likes of Photoshop in HTML5. That’s where Native Client comes it.”
-TechCrunch
Pexe Size
C++ exceptions and SIMD
Translation
Time
Developer Responsivity
Thank You!
http://gonacl.com
sehr@google.com, mackinlay@google.com
native-client-discuss@googlegroups.com
Thank You!
http://gonacl.com
sehr@google.com, mackinlay@google.com
native-client-discuss@googlegroups.com
Thank You!
http://gonacl.com
sehr@google.com, mackinlay@google.com
native-client-discuss@googlegroups.com
How Do I Use It?
Developers
Backup
Subtitle Placeholder
Running a PNaCl Application
Native Client Sandbox
NaCl Runtime
air_mech_x86_64.nexe
gonacl.com
Running a PNaCl Application
Native Client Sandbox
air_mech_x86_64.nexe
Browser data
Browser APIs
OS APIs
Try PNaCl in Chrome 31
Try the PNaCl Examples extension
We want your feedback at http://gonacl.com
Try our demos
PNaCl SDK
PPAPI
Writing a Secure Plugin
Porting an Application to NaCl
Porting an Application to PNaCl
Native Client and the Chrome Web Store
Native Client Limitations
"No ISAs in the web platform"
Portable Native Client
Developer
User
Distribution
Portable Native Client Distribution
Developer
User
Distribution
The Compatibility Story with Pepper.js
Pepper.js is a JavaScript library that enables the compilation of native Pepper applications into JavaScript using Emscripten.
The Compatibility Story with Pepper.js
Our Failures, and How We Address Them
“40% of people abandon a website that takes more than 3 seconds to load”
Sean Work
KISSmetrics
PNaCl Progress Events
Native Client Process
llc.nexe
Stream .pexe
from URL
ssh.nexe
Write .nexe
"progress" events
function moduleLoadProgress(event) {
var loadPercent = 0.0;
var loadPercentString;
if (event.lengthComputable && event.total > 0) {
loadPercent = event.loaded / event.total * 100.0;
loadPercentString = loadPercent + '%';
} else {
// The total length is not yet known.
loadPercent = -1.0;
loadPercentString = 'Computing...';
}
appendToEventLog('progress: ' + loadPercentString +
' (' + event.loaded + ' of ' + event.total + ' bytes)');
}
JavaScript
Translation Time and Application Architecture
Download .pexe
Download assets
Translate .pexe
Time
.pexe requests assets
Application runs
Download assets
Application runs
JavaScript requests assets
Download .pexe
Translate .pexe
pig.jpg
slingshot.jpg
redbird.jpg
bluebird.jpg
yellowbird.jpg
...
filelist.txt
Translation Options for PNaCl Applications
{� "files": {},
"program": {� "portable": {� "pnacl-translate": {� "url": "ssh.pexe",
"-O": level� }� }� }�}
Translate Speed and Execution Speed
.nmf
level | translation time | perf vs. native |
0 | 1x | ~50% |
2 | ~2-3x | ~80+% |
HTML
Translation Rate
| O0 |
x86 (high-end) | ~750 KB/s |
ARM (Chromebook) | ~130 KB/s |
Translation Rate
| O0 | O2 |
x86 (high-end) | ~750 KB/s | ~250 KB/s |
ARM (Chromebook) | ~130 KB/s | ~70 KB/s |
A Taste of Things to Come
PNaCl in Chrome
PNaCl Roadmap
Developer Features
| Launch |
x86-32, x86-64, ARM | yes |
pthreads, atomics | yes |
SIMD | no |
C++ Exception Handling | no |
Tools, Examples, Libraries, Debugger | yes |
Dynamic Linking | no |
JIT Support | no |
PNaCl Roadmap
Developer Features
| Launch | First update |
x86-32, x86-64, ARM | yes | |
pthreads, atomics | yes | |
SIMD | no | no |
C++ Exception Handling | no | yes |
Tools, Examples, Libraries, Debugger | yes | |
Dynamic Linking | no | no |
JIT Support | no | no |
PNaCl Roadmap
Developer Features
| Launch | First update | Second update |
x86-32, x86-64, ARM | yes | | |
pthreads, atomics | yes | | |
SIMD | no | no | |
C++ Exception Handling | no | yes | yes |
Tools, Examples, Libraries, Debugger | yes | | |
Dynamic Linking | no | no | ??? |
JIT Support | no | no | ??? |
PNaCl Roadmap
User Features
| Launch |
Translation Cache | yes |
Developer Choice of Optimization Level | yes |
Streaming Translation | yes |
Multicore Translation | no |
Custom Fast Translator | no |
PNaCl Roadmap
User Features
| Launch | First update |
Translation Cache | yes | |
Developer Choice of Optimization Level | yes | |
Streaming Translation | yes | |
Multicore Translation | no | ??? |
Custom Fast Translator | no | no |
PNaCl Roadmap
User Features
| Launch | First update | Second update |
Translation Cache | yes | | |
Developer Choice of Optimization Level | yes | | |
Streaming Translation | yes | | |
Multicore Translation | no | ??? | yes |
Custom Fast Translator | no | no | ??? |
Portable Native Client
Building a Portable Native Client Application
C++ Source Code
gcc/g++
.nexe
Building a Portable Native Client Application
C++ Source Code
gcc/g++
.nexe
.nexe
.nmf file (manifest)
<embed name="nacl_module"
id="air_mech"
src="air_mech.nmf"
type="application/x-nacl" />
HTML
.nexe
Instruction Set Architecture (ISA) Dependency
{
"files": {},
"program": {
"x86-64": { "url": "air_mech_x86_64.nexe" },
"x86-32": { "url": "air_mech_x86_32.nexe" },
"arm": { "url": "air_mech_arm.nexe" }
}
}
NaCl Manifest File
.nmf
Every supported ISA needs an entry here
Which ISA
Where to find its executable
Running a Native Client Application
<embed name="nacl_module"
id="air_mech"
src="air_mech.nmf"
type="application/x-nacl" />
Native Client Process
air_mech_x86_64.nexe
Loads correct
.nexe
HTML
{
"files": {},
"program": {
"x86-64": { "url": "air_mech_x86_64.nexe" },
"x86-32": { "url": "air_mech_x86_32.nexe" },
"arm": { "url": "air_mech_arm.nexe" }
}
}
air_mech.nmf
embed reads
manifest
.nmf
So We're Done, Right?
Related Technology
The PNaCl Translator
"ssh.pexe"
no translation exists
Native Client Process
llc.nexe
Send .nexe
from cache
Native Client Process
ssh_x86_64.nexe
Translation
Cache
Stream .pexe
from URL
ssh_x86_64.nexe
Write .nexe
Save ssh_x86_64.nexe