SlideShare a Scribd company logo
1 of 74
Download to read offline
Hi, my name is Chad Austin, and I’m here to tell you about
what led IMVU to select Emscripten as a key part of our
strategy to have a single C++ engine across all platforms,
including web browsers.




                                                             1
LLVM is an open source compiler infrastructure, mostly
commonly used as the foundation of the clang C/C++
compiler.
Emscripten translates LLVM into JavaScript suitable for web
browsers.




                                                              2
3
4
5
6
IMVU is a place where members use 3D avatars to meet new
people, chat, and play games.




                                                           7
8
Today IMVU is a downloadable application for Windows and
Mac.




                                                           9
10
11
Making best use of the hardware is key on mobile devices.




                                                            12
13
14
15
16
My testing methodology: run the benchmark in all compilers
with all optimization settings and pick the fastest.




                                                             17
At this point, I’m willing to pay a reduction in performance in
order to have a single C++ engine codebase.




                                                                  18
19
Same benchmark as before for comparison purposes.




                                                    20
asm.js is a big win. (But lack of SIMD makes it still slower
than native.)




                                                               21
So let’s look at a benchmark that doesn’t rely so much on
SIMD.




                                                            22
23
24
25
26
27
28
29
30
Note the excessive redundancy of the generated code. After Emscripten runs,
a series of JavaScript optimizers transform the generated code until it looks
like this:




                                                                                31
32
33
34
35
36
37
Note that LLVM has no high-level control flow, just branch
instructions.




                                                             38
Naive translation to JS results in an infinite loop containing a
switch. In effect, implementing goto.




                                                                   39
40
41
42
43
44
45
46
Another reason we prefer SCons over emcc is in the case where a change to
some C++ doesn’t necessarily modify the generated code. In that case, emcc
would attempt to relink, the slowest part, whereas SCons would know that
the linker inputs haven’t changed and finish the build early.




                                                                             47
48
Engine.min.js is the most important build, but it’s painful to
build and work with.
Engine.debug.js is ideal for debugging, but still takes time to
build.
Engine.iteration.js is for running unit tests.




                                                                  49
50
51
52
53
Pointer_stringify is a helper that takes the char* address and
creates a JS string from the heap.




                                                                 54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

More Related Content

Viewers also liked

Trace Lessons Learned H4Dip Stanford 2016
Trace Lessons Learned H4Dip Stanford 2016 Trace Lessons Learned H4Dip Stanford 2016
Trace Lessons Learned H4Dip Stanford 2016 Stanford University
 
Aggregate db Lessons Learned H4Dip Stanford 2016
Aggregate db Lessons Learned H4Dip Stanford 2016Aggregate db Lessons Learned H4Dip Stanford 2016
Aggregate db Lessons Learned H4Dip Stanford 2016Stanford University
 
Peacekeeping Lessons Learned H4Dip Stanford 2016
Peacekeeping Lessons Learned H4Dip Stanford 2016Peacekeeping Lessons Learned H4Dip Stanford 2016
Peacekeeping Lessons Learned H4Dip Stanford 2016Stanford University
 
Space Evaders Lessons Learned H4Dip Stanford 2016
Space Evaders Lessons Learned H4Dip Stanford 2016Space Evaders Lessons Learned H4Dip Stanford 2016
Space Evaders Lessons Learned H4Dip Stanford 2016Stanford University
 
Exodus Lessons Learned H4Dip Stanford 2016
Exodus Lessons Learned H4Dip Stanford 2016Exodus Lessons Learned H4Dip Stanford 2016
Exodus Lessons Learned H4Dip Stanford 2016Stanford University
 
Hacking CT Lessons Learned H4Dip Stanford 2016
Hacking CT Lessons Learned H4Dip Stanford 2016Hacking CT Lessons Learned H4Dip Stanford 2016
Hacking CT Lessons Learned H4Dip Stanford 2016Stanford University
 
Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016
Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016
Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016Stanford University
 

Viewers also liked (12)

Nova Stanford 2016
Nova Stanford 2016Nova Stanford 2016
Nova Stanford 2016
 
SalesStash Berkeley 2016
SalesStash Berkeley 2016SalesStash Berkeley 2016
SalesStash Berkeley 2016
 
Trace Lessons Learned H4Dip Stanford 2016
Trace Lessons Learned H4Dip Stanford 2016 Trace Lessons Learned H4Dip Stanford 2016
Trace Lessons Learned H4Dip Stanford 2016
 
Aggregate db Lessons Learned H4Dip Stanford 2016
Aggregate db Lessons Learned H4Dip Stanford 2016Aggregate db Lessons Learned H4Dip Stanford 2016
Aggregate db Lessons Learned H4Dip Stanford 2016
 
Peacekeeping Lessons Learned H4Dip Stanford 2016
Peacekeeping Lessons Learned H4Dip Stanford 2016Peacekeeping Lessons Learned H4Dip Stanford 2016
Peacekeeping Lessons Learned H4Dip Stanford 2016
 
Space Evaders Lessons Learned H4Dip Stanford 2016
Space Evaders Lessons Learned H4Dip Stanford 2016Space Evaders Lessons Learned H4Dip Stanford 2016
Space Evaders Lessons Learned H4Dip Stanford 2016
 
Exodus Lessons Learned H4Dip Stanford 2016
Exodus Lessons Learned H4Dip Stanford 2016Exodus Lessons Learned H4Dip Stanford 2016
Exodus Lessons Learned H4Dip Stanford 2016
 
Hacking CT Lessons Learned H4Dip Stanford 2016
Hacking CT Lessons Learned H4Dip Stanford 2016Hacking CT Lessons Learned H4Dip Stanford 2016
Hacking CT Lessons Learned H4Dip Stanford 2016
 
Exit strategy Berkeley 2016
Exit strategy Berkeley 2016Exit strategy Berkeley 2016
Exit strategy Berkeley 2016
 
HomeSlice Berkeley 2016
HomeSlice Berkeley 2016HomeSlice Berkeley 2016
HomeSlice Berkeley 2016
 
Delphi Berkeley 2016
Delphi Berkeley 2016Delphi Berkeley 2016
Delphi Berkeley 2016
 
Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016
Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016
Fatal journeys (Team 621) Lessons Learned H4Dip Stanford 2016
 

Similar to Multiplatform C++ on the Web with Emscripten

Minko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.jsMinko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.jsMinko3D
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1Sisir Ghosh
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5David Voyles
 
The Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceThe Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceIntel® Software
 
Adventures in docker compose
Adventures in docker composeAdventures in docker compose
Adventures in docker composeLinkMe Srl
 
Freedreno on Android – XDC 2023
Freedreno on Android          – XDC 2023Freedreno on Android          – XDC 2023
Freedreno on Android – XDC 2023Igalia
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performancekaven yan
 
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...Embarcados
 
TestUpload
TestUploadTestUpload
TestUploadZarksaDS
 
(java2days) Is the Future of Java Cloudy?
(java2days) Is the Future of Java Cloudy?(java2days) Is the Future of Java Cloudy?
(java2days) Is the Future of Java Cloudy?Steve Poole
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfRichHagarty
 
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...RichHagarty
 
javalightspeed-jakartatech-2023.pdf
javalightspeed-jakartatech-2023.pdfjavalightspeed-jakartatech-2023.pdf
javalightspeed-jakartatech-2023.pdfRichHagarty
 

Similar to Multiplatform C++ on the Web with Emscripten (20)

Minko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.jsMinko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.js
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1
 
Node js
Node jsNode js
Node js
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
Where should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and moreWhere should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and more
 
The Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceThe Next Leap in JavaScript Performance
The Next Leap in JavaScript Performance
 
Web Leaps Forward
Web Leaps ForwardWeb Leaps Forward
Web Leaps Forward
 
Adventures in docker compose
Adventures in docker composeAdventures in docker compose
Adventures in docker compose
 
Freedreno on Android – XDC 2023
Freedreno on Android          – XDC 2023Freedreno on Android          – XDC 2023
Freedreno on Android – XDC 2023
 
Java vs .Net
Java vs .NetJava vs .Net
Java vs .Net
 
Asm.js introduction
Asm.js introductionAsm.js introduction
Asm.js introduction
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performance
 
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
 
TestUpload
TestUploadTestUpload
TestUpload
 
(java2days) Is the Future of Java Cloudy?
(java2days) Is the Future of Java Cloudy?(java2days) Is the Future of Java Cloudy?
(java2days) Is the Future of Java Cloudy?
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdf
 
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
 
javalightspeed-jakartatech-2023.pdf
javalightspeed-jakartatech-2023.pdfjavalightspeed-jakartatech-2023.pdf
javalightspeed-jakartatech-2023.pdf
 

Multiplatform C++ on the Web with Emscripten

  • 1. Hi, my name is Chad Austin, and I’m here to tell you about what led IMVU to select Emscripten as a key part of our strategy to have a single C++ engine across all platforms, including web browsers. 1
  • 2. LLVM is an open source compiler infrastructure, mostly commonly used as the foundation of the clang C/C++ compiler. Emscripten translates LLVM into JavaScript suitable for web browsers. 2
  • 3. 3
  • 4. 4
  • 5. 5
  • 6. 6
  • 7. IMVU is a place where members use 3D avatars to meet new people, chat, and play games. 7
  • 8. 8
  • 9. Today IMVU is a downloadable application for Windows and Mac. 9
  • 10. 10
  • 11. 11
  • 12. Making best use of the hardware is key on mobile devices. 12
  • 13. 13
  • 14. 14
  • 15. 15
  • 16. 16
  • 17. My testing methodology: run the benchmark in all compilers with all optimization settings and pick the fastest. 17
  • 18. At this point, I’m willing to pay a reduction in performance in order to have a single C++ engine codebase. 18
  • 19. 19
  • 20. Same benchmark as before for comparison purposes. 20
  • 21. asm.js is a big win. (But lack of SIMD makes it still slower than native.) 21
  • 22. So let’s look at a benchmark that doesn’t rely so much on SIMD. 22
  • 23. 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. 27
  • 28. 28
  • 29. 29
  • 30. 30
  • 31. Note the excessive redundancy of the generated code. After Emscripten runs, a series of JavaScript optimizers transform the generated code until it looks like this: 31
  • 32. 32
  • 33. 33
  • 34. 34
  • 35. 35
  • 36. 36
  • 37. 37
  • 38. Note that LLVM has no high-level control flow, just branch instructions. 38
  • 39. Naive translation to JS results in an infinite loop containing a switch. In effect, implementing goto. 39
  • 40. 40
  • 41. 41
  • 42. 42
  • 43. 43
  • 44. 44
  • 45. 45
  • 46. 46
  • 47. Another reason we prefer SCons over emcc is in the case where a change to some C++ doesn’t necessarily modify the generated code. In that case, emcc would attempt to relink, the slowest part, whereas SCons would know that the linker inputs haven’t changed and finish the build early. 47
  • 48. 48
  • 49. Engine.min.js is the most important build, but it’s painful to build and work with. Engine.debug.js is ideal for debugging, but still takes time to build. Engine.iteration.js is for running unit tests. 49
  • 50. 50
  • 51. 51
  • 52. 52
  • 53. 53
  • 54. Pointer_stringify is a helper that takes the char* address and creates a JS string from the heap. 54
  • 55. 55
  • 56. 56
  • 57. 57
  • 58. 58
  • 59. 59
  • 60. 60
  • 61. 61
  • 62. 62
  • 63. 63
  • 64. 64
  • 65. 65
  • 66. 66
  • 67. 67
  • 68. 68
  • 69. 69
  • 70. 70
  • 71. 71
  • 72. 72
  • 73. 73
  • 74. 74