@@ -683,6 +683,40 @@ \subsection{Benchmarks}
683683Compiler, and JavaScript engines themselves; see further discussion
684684in the Summary.
685685
686+ \subsection {Limitations }
687+
688+ Emscripten's compilation approach, as has been described in this Section so far,
689+ is to generate `natural' JavaScript, as close as possible to normal JavaScript
690+ on the web, so that modern JavaScript engines perform well on it. In particular,
691+ we try to generate `normal' JavaScript operations, like regular addition and
692+ multiplication and so forth. This is a very
693+ different approach than, say, emulating a CPU on a low level, or for the case
694+ of LLVM, writing an LLVM bitcode interpreter in JavaScript. The latter approach
695+ has the benefit of being able to run virtually any compiled code, at the cost
696+ of speed, whereas Emscripten makes a tradeoff in the other direction. We will
697+ now give a summary of some of the limitations of Emscripten's approach.
698+
699+ \begin {itemize }
700+ \item \textbf {64-bit Integers }: JavaScript numbers are all 64-bit doubles, with engines
701+ typically implementing them as 32-bit integers where possible for speed.
702+ A consequence of this is that it is impossible to directly implement
703+ 64-bit integers in JavaScript, as integer values larger than 32 bits will become doubles,
704+ with only 53 bits for the significand. Thus, when Emscripten uses normal
705+ JavaScript addition and so forth for 64-bit integers, it runs the risk of
706+ rounding effects. This could be solved by emulating 64-bit integers,
707+ but it would be much slower than native code.
708+ \item \textbf {Multithreading }: JavaScript has Web Workers, which are additional
709+ threads (or processes) that communicate via message passing. There is no
710+ shared state in this model, which means that it is not directly possible
711+ to compile multithreaded code in C++ into JavaScript. A partial solution
712+ could be to emulate threads, without Workers, by manually controlling
713+ which blocks of code run (a variation on the switch in a loop construction
714+ mentioned earlier) and manually switching between threads every so often.
715+ However, in that case there would not be any utilization
716+ of additional CPU cores, and furthermore performance would be slow due to not
717+ using normal JavaScript loops.
718+ \end {itemize }
719+
686720\section {Emscripten's Architecture }
687721\label {sec:emarch }
688722
@@ -997,12 +1031,7 @@ \section{Summary}
9971031addition, by compiling the runtimes of languages which are implemented in C and C++,
9981032we can run them on the web as well, for example Python and Lua.
9991033
1000- Important future tasks for Emscripten are to broaden its
1001- standard library and to support additional types of code, such as
1002- multithreaded code (JavaScript Web Workers do not support shared state,
1003- so this is not possible directly, but it can be emulated in various ways).
1004-
1005- But perhaps the largest future goal of Emscripten is to improve the performance of
1034+ Perhaps the largest future goal of Emscripten is to improve the performance of
10061035the generated code. As we have seen, speeds of around $ 1 /10 $ th that of
10071036GCC are possible, which is already good enough for many purposes, but
10081037can be improved much more. The code Emscripten generates will become faster
0 commit comments