This post will explain what V8 is, how it works, the features that enable its speed, security, and efficiency, and how V8 enables Azion’s Edge Functions to bring serverless computing to the edge of the network.
How Does V8 Work?
To execute code with both speed and precision, the V8 Engine must determine whether bytecode should be run as is or further optimized into machine code. This evaluation is performed by the profiler, which checks bytecode to see if it can be further optimized into machine code by the compiler. The compiler performs optimizations on the fly, making assumptions based on available profiling data. If any assumptions prove to be incorrect, code is deoptimized into bytecode before being executed. A visual representation of this process is included below.
What Makes V8 Fast, Efficient, and Secure?
Four features that contribute to V8’s performance, efficiency, and security are:
- efficient garbage collection;
- use of hidden classes;
- inline caching; and
- fine-grained sandboxing.
Efficient Garbage Collection
Garbage collection is a process that reclaims memory by eliminating objects that are no longer needed. Although this optimizes memory use, it can slow down processing, as processes must pause while garbage collection is taking place. However, as explained on the Chromium Project’s GitHub page, V8’s garbage collector “minimizes the impact of stopping the application” by processing “only part of the object heap in most garbage collection cycles.” In addition, the garbage collector “always knows where all objects and pointers are in memory. This avoids falsely identifying objects as pointers which can result in memory leaks.” The result is fast object allocation, short garbage collection pauses, and no memory fragmentation.
Hidden Classes and Inline Caching
Inline caching, as noted in a 2016 GitHub post, inline caching “takes an operation that typically requires a bunch of important checks and generates specialized code for specific, known scenarios, where the specialized code doesn’t contain those checks.” As a result, V8 is able to generate machine code quickly and efficiently.
How Does V8 Enable Azion’s Edge Functions?
How Does Serverless Computing Work?
Edge Functions is a product that lets developers easily build and run event-driven serverless functions at the edge of the network. When functions are requested, they execute on the Edge Node closest to end users and scale automatically, without the need to provision or manage resources. As a result, users are able to pay only for the resources used and dramatically reduce the time spent on configuration and rote management tasks.
However, combining the ease of use and cost efficiency of serverless with the speed of edge computing presents many challenges behind the scenes. Serverless computing makes automatic scaling possible by atomizing applications into discrete tasks that are small, independent, and stateless. Because state is not preserved between invocations, functions can be run when they are needed and stop running during periods of inactivity. But this process of stopping and starting takes time and computing resources, particularly when functions are run inside of containers, as is the case with AWS Lambda and cloud providers’ serverless solutions.
How Does V8 Enhance Serverless Computing?
Efficient resource use is not only good for the planet, it’s good for businesses who choose to build with Azion. Eliminating the need to run functions in containers means less configuration, since container-based solutions require developers to allocate a certain amount of memory to each function ahead of time. In addition, less computing power means less operational costs.
Finally, and most crucially for edge computing, running functions in a multitenant environment results in lower latency. Functions that are run in containers are spun down during periods of inactivity; when a function is called again, its container must be spun back up, resulting in a half-second delay known as a cold start. By using V8 to isolate each function, rather than containers, Azion eliminates cold starts, thus reducing latency and making performance more reliable and predictable.
Running thousands of containers in distributed edge locations all over the world would be cost-prohibitive; that’s why cloud solutions like AWS Lambda are delivered from centralized data centers. Because multitenancy enables much more efficient resource use, Azion is able to run event-driven functions in distributed edge locations all over the world, executing them when and where they’re needed at the PoP closest to the end user. In addition, less time transmitting data back and forth means less time spent executing each function, resulting in lower costs for compute time each time a function is called.
Advantages of Edge Functions
- resource efficiency;
- cost efficiency; and
- ease of use.
As a result, Edge Functions is an ideal solution for a variety of use cases, such as:
- easily modernizing monolithic applications;
- building ultra-low latency applications;
- event-driven programming;
- reducing costs;
- adding third-party functionality to applications; and
- increasing agility and expediting time to market.