Recent from talks
Nothing was collected or created yet.
Chakra (JScript engine)
View on Wikipedia| Chakra | |
|---|---|
| Developer | Microsoft |
| Initial release | 2009 |
| Written in | C++ |
| Operating system | Microsoft Windows |
| Type | JScript engine |
| License | Proprietary |
Chakra is a JScript engine used in the Internet Explorer web browser, both developed by Microsoft as proprietary software.
Microsoft later developed a new JavaScript engine for its Microsoft Edge Legacy browser, which is confusingly also named Chakra. Microsoft Edge changed to V8 (JavaScript engine) in 2020.
Features
[edit]A distinctive feature of the engine is that it just-in-time (JIT) compiles scripts on a separate central processing unit (CPU) core, parallel to the web browser.[1][2] Though Microsoft has in the past pointed out that other elements, such as rendering and marshalling, are just as important for a browser's overall performance,[3] their improvements to the engine were in response to evolving competing browsers, compared to which IE8 was lagging behind in terms of client-side script processing speed.[4]
History
[edit]SunSpider tests performed on November 18, 2009 showed the Professional Developers Conference (PDC) version of IE9 executing scripts much faster than IE8, but slower than Firefox 3.6, Chrome 4, and WebKit Nightly.[3] The same test performed on March 15, 2010 showed the first IE9 Platform Preview (using the then-current version of Chakra) to be faster than Firefox (with SpiderMonkey), but slower than Safari (with SquirrelFish Extreme), Chrome (with V8), and Opera (with Carakan).
On March 8, 2011, Microsoft published results showing the 32-bit Internet Explorer 9 to be faster than Safari, Firefox (with TraceMonkey), Chrome, and Opera.[5]
March 2011 performance tests for ZDNET concluded that Internet Explorer 9 (32-bit), Chrome 10, and Firefox 4 release candidate were "pretty evenly matched."[6]
In 2012, subsequent versions of Chakra, such as the version included in Internet Explorer 10, introduced additional performance changes, including JIT compiling on x86-64 and ARM architectures, and optimizations related to floating point math and garbage collection.[7]
References
[edit]- ^ Vaughan-Nichols, Steven J. (March 10, 2011). "Chrome 10 vs. Internet Explorer 9 Reconsidered". ZDNet. Retrieved 2011-03-21.
- ^ Muchmore, Michael (March 16, 2010). "Internet Explorer 9: An Early Look". PC Magazine. Retrieved March 19, 2010.
- ^ a b Hachamovitch, Dean (November 23, 2009). "An Early Look At IE9 for Developers". IEBlog on Microsoft Developer Network. Microsoft. Retrieved March 19, 2010.
- ^ Hachamovitch, Dean (March 18, 2010). "HTML5, Hardware Accelerated: First IE9 Platform Preview Available for Developers". IEBlog on Microsoft Developer Network. Microsoft. Retrieved March 19, 2010.
- ^ "WebKit Sunspider JavaScript Benchmark Results". Internet Explorer 9 Platform Demos: Test Drive. Microsoft. Archived from the original on 2011-03-24. Retrieved March 19, 2010.
- ^ Kingsley-Hughes, Adrian (March 15, 2011). "IE9 vs Chrome 10 vs Firefox 4 RC vs Opera 11.01 vs Safari 5 - The BIG browser benchmark!". ZDNet. Archived from the original on 2011-03-20. Retrieved 2011-03-21.
- ^ "Advances in JavaScript Performance in IE10 and Windows 8". Microsoft. Retrieved October 24, 2013.
Chakra (JScript engine)
View on GrokipediaOverview
Definition and Purpose
Chakra is a high-performance JavaScript engine developed by Microsoft, serving as the core component for executing JScript, Microsoft's implementation of the ECMAScript scripting language specification.[10][1] Introduced in Internet Explorer 9, it interprets, compiles, and executes JavaScript code in parallel, leveraging multiple CPU cores to generate efficient machine code while maintaining foreground interpretation for seamless performance.[1] The primary purpose of Chakra is to enable dynamic web content rendering, Document Object Model (DOM) manipulation, and client-side scripting within Internet Explorer browsers starting from version 9, thereby enhancing the interactivity and responsiveness of web applications.[1] By integrating natively with the browser's DOM, Chakra eliminates intermediate processing layers, allowing JavaScript to interact directly with web page elements for faster execution of scripts that drive user interfaces and behaviors.[1] This design supports the creation of rich, script-driven experiences in web pages, aligning with the demands of modern web development. Unlike general-purpose JavaScript engines such as V8 or SpiderMonkey, Chakra is tailored specifically for JScript compatibility to ensure seamless operation in Microsoft's ecosystem, while progressively incorporating support for contemporary ECMAScript features like those in ES2015 for broader interoperability.[11][4] Initially developed as proprietary software under exclusive Microsoft ownership, Chakra accepted no external contributions until its core components were open-sourced in 2016.[4]Standards Compliance
Chakra, the JavaScript engine powering Microsoft's JScript implementation, establishes ECMAScript 3 (ES3) as its foundational baseline to ensure compatibility with legacy JScript code from earlier Internet Explorer versions. This adherence to ES3 allows Chakra to execute scripts originally written for JScript, which was designed as Microsoft's dialect of the ECMAScript standard, incorporating core language features like object prototypes, functions, and basic control structures without introducing breaking changes. Chakra achieved full ECMAScript 5 (ES5) compliance starting with Internet Explorer 9.[12] It progressively added support for later ECMAScript editions, reaching substantial compliance with ECMAScript 6 (ES2015) in Microsoft Edge.[13] Key ES6 additions include block-scoped variables withlet and const, arrow functions for concise syntax, and native Promises for asynchronous programming, enabling more modern JavaScript patterns while maintaining backward compatibility.[13] For ECMAScript 2016 and beyond, Chakra provided partial or experimental implementations, such as async/await functions, which were introduced in Microsoft Edge previews but not fully available in Internet Explorer 11.[14]
The open-sourced ChakraCore provided broad support for ECMAScript 2015 (ES6) and select features from later editions.[15]
Beyond standard ECMAScript compliance, Chakra includes Microsoft-specific extensions rooted in JScript's design, such as direct integration with ActiveX controls for embedding native Windows components in scripts.[16] These extensions also facilitate interoperability with VBScript through the Windows Script Host, allowing JScript code to interact with COM objects and shared scripting environments for tasks like automation and data access.[17]
Chakra's conformance to ECMAScript standards has been verified using the official Test262 conformance suite, achieving full ES5 compliance in Internet Explorer 9 with only minimal failures across thousands of tests.[12] By the era of Microsoft Edge, Chakra improved to near-complete ES6 support, passing the majority of Test262 tests for those features and establishing itself as one of the leading engines for modern JavaScript adherence at the time.[18]
Development History
Origins in Internet Explorer
Development of the Chakra JavaScript engine began in 2008 as a response to the limitations of the existing JScript engine used in Internet Explorer 8 (IE8), which relied on an interpreter-based approach that struggled with the increasing demands of complex web applications requiring faster script execution.[19][20] By this time, web development had evolved significantly, with dynamic sites and early single-page applications pushing browsers to handle more intensive JavaScript workloads, exposing the performance bottlenecks of legacy engines like JScript.[21] The primary motivations for creating Chakra were to dramatically enhance JavaScript performance through just-in-time (JIT) compilation, enabling the engine to generate machine code from scripts at runtime for greater efficiency compared to interpretation. This shift was essential for Microsoft to regain competitiveness against emerging rivals, such as Google's V8 engine in Chrome and Mozilla's SpiderMonkey in Firefox, which had set new benchmarks for speed in modern browsing scenarios.[2][22][23] Chakra was first publicly demonstrated in the Internet Explorer 9 Platform Preview released on March 16, 2010, and made its full debut with the release of Internet Explorer 9 on March 14, 2011, representing Microsoft's first implementation of a JIT-compiled JavaScript engine in its flagship browser.[24][25][2] The project was spearheaded by the Internet Explorer development team at Microsoft, with a strong emphasis on seamless integration with the Windows operating system to leverage native platform capabilities for optimized rendering and execution.[26] This foundation allowed Chakra to support accelerated hardware features and tighter OS coupling, distinguishing it from more general-purpose engines.Version Evolution
With the release of Internet Explorer 10 in 2012, Chakra introduced stricter compliance with ECMAScript 5 (ES5), including full support for strict mode, alongside initial optimizations leveraging hardware acceleration to enhance rendering and execution speed.[27] Internet Explorer 11, launched in 2013, marked a significant advancement with complete ES5 support and support for certain ES6 features like typed arrays, while incorporating a tiered just-in-time (JIT) compilation approach to reduce startup times through efficient interpretation and progressive optimization.[28] In 2015, Chakra transitioned to power the new Microsoft Edge browser, built on the EdgeHTML rendering engine rather than Trident, enabling adaptations for modern web standards and continued proprietary enhancements until Edge's shift away from EdgeHTML in 2019.[29] Key milestones in Chakra's evolution included cumulative performance improvements reaching up to 2x over the JScript engine in Internet Explorer 8, as demonstrated in benchmarks like SunSpider and Kraken, which highlighted gains in JavaScript execution efficiency across versions.[30] Internally, Chakra's versioning aligned closely with Internet Explorer and Edge builds, starting with version 1.0 in Internet Explorer 9 and progressing through iterative cores integrated into EdgeHTML platforms.[31] The evolved core was later open-sourced as ChakraCore in 2016.[32]Open-Sourcing as ChakraCore
In December 2015, during a presentation at JSConf US, Microsoft announced its intention to open-source the core components of the Chakra JavaScript engine, rebranded as ChakraCore. The initial release occurred on January 13, 2016, when the source code was published on GitHub under the permissive MIT license.[32] This version focused on the engine's foundational elements, deliberately excluding browser-specific integrations such as DOM and UI bindings tailored for Internet Explorer or Microsoft Edge, which allowed ChakraCore to function as a lightweight, embeddable JavaScript runtime suitable for server-side environments, desktop applications, or Node.js-compatible setups.[32][18] Microsoft's motivations for this open-sourcing effort centered on building a collaborative development model to accelerate innovation and broaden the engine's applicability beyond proprietary browser contexts. By releasing ChakraCore, the company aimed to invite global community input for enhancements, ensure greater alignment with evolving open web standards like ECMAScript specifications, and reinforce its commitment to the open-source ecosystem amid a broader cultural shift toward transparency in software development.[32][33] This approach was intended to leverage external expertise for ongoing improvements while positioning ChakraCore for cross-platform uses, including potential integrations in cloud services and Internet of Things applications.[34] Following its launch, ChakraCore quickly gained traction among external developers, who contributed pull requests addressing bug fixes, performance tweaks, and expanded support for ECMAScript 2017 features such as async/await and shared memory.[5] Notable early adoption included the Node-ChakraCore project, an experimental fork of Node.js powered by ChakraCore instead of V8, which demonstrated its viability in server-side JavaScript execution and attracted further community experimentation.[35] The repository saw sustained development activity through 2020, with regular releases incorporating community-submitted enhancements; however, following the transition of Microsoft Edge to the Chromium engine, active development ceased, with the final release (v1.11.24) in December 2020 and security updates provided until March 2021.[5]Technical Architecture
Parsing and Execution Model
Chakra processes JavaScript source code through a multi-stage parsing pipeline designed for efficiency and on-demand execution. Upon receiving input, the engine performs an initial quick parse to detect syntax errors without full analysis, ensuring rapid feedback during development or loading.[36] If no errors are found, full parsing occurs lazily when a function is first invoked, transforming the source into an abstract syntax tree (AST) that represents the code's structure in a platform-independent manner.[36] This AST is then lowered into platform-agnostic bytecode, a compact intermediate representation optimized for subsequent interpretation, which supports features like dynamic typing and scope resolution.[36] Bytecode generation enables caching via APIs such as JsSerializeScript, allowing applications to store and reload parsed scripts for faster startup in repeated executions.[3] The interpreter phase handles initial code execution to prioritize quick startup times, directly running the generated bytecode in a fast, non-optimizing manner. This interpreter manages core JavaScript behaviors, including dynamic type handling—where variables and operations adapt at runtime—and scope resolution, which determines variable accessibility across function contexts and closures.[36] By executing bytecode interpretively, Chakra achieves low-latency launches for short scripts or cold starts, while gathering runtime profiles like type information to inform later optimizations, though the core interpretation remains focused on straightforward, unoptimized traversal.[36] This phase transitions seamlessly to compiled code for frequently invoked functions, enhancing overall performance without interrupting execution flow.[36] Chakra's runtime environment employs a generational mark-and-sweep garbage collector for automatic memory management, dividing objects into young and old generations to efficiently reclaim unused space and minimize pauses.[36] The collector operates concurrently in the background, performing partial collections that include marking reachable objects, rescanning for accuracy, and sweeping freed memory, which supports scalable handling of large object graphs in production workloads.[36] In 64-bit configurations, this system accommodates substantial heap sizes, enabling robust memory usage for memory-intensive applications while triggering out-of-memory errors when limits are exceeded.[37] Error handling integrates diagnostics throughout the pipeline, with the initial parse flagging syntax errors immediately and the interpreter capturing runtime exceptions during bytecode execution.[36] For thrown errors, particularly those deriving from the Error prototype, Chakra generates stack traces that map back to original source lines, providing developers with precise call stack information for debugging.[38] The threading model adheres to JavaScript's single-threaded execution paradigm, where all script code runs on a primary thread to avoid concurrency issues in shared state.[3] Asynchronous operations integrate via an event loop mechanism, queuing callbacks and promises for non-blocking handling without multi-threading the core runtime, though background threads may assist ancillary tasks like garbage collection.[36] This design ensures deterministic behavior for synchronous code while supporting scalable async patterns through host environment integrations.[3]Just-In-Time Compilation
Chakra's just-in-time (JIT) compilation mechanism employs a tiered approach to balance startup latency and peak performance, consisting of three execution tiers: an initial interpreter for rapid bytecode execution, a simple JIT compiler that generates quick but less optimized machine code for warming up hot functions, and a full optimizing JIT compiler that produces highly tuned code incorporating advanced transformations like inlining and loop unrolling.[36] This tiered strategy allows the engine to progressively optimize code based on runtime behavior, with compilation occurring on background threads to avoid blocking the main execution thread.[36] Hot code identification begins during interpretation, where the engine collects profile data on invocation counts, type information, and execution paths for functions and loops. When a function reaches predefined thresholds—such as 25 invocations for promotion to the simple JIT tier and 20,000 for the full JIT tier—the relevant code is queued for compilation, enabling dynamic adaptation to frequently executed paths while minimizing unnecessary compilations.[39][36] The JIT compilers apply several key optimization techniques to enhance efficiency. Type specialization leverages profiled type information to assume stable types for variables and objects, allowing the generation of faster, type-specific operations instead of generic handling. Dead code elimination removes instructions that do not affect program outcomes, while register allocation optimizes the use of CPU registers to reduce memory accesses and improve instruction throughput. These optimizations are guided by the interpreter's profile data to infer common usage patterns.[36] Chakra supports JIT backends for x86, x64, and ARM architectures, ensuring compatibility across diverse hardware platforms. Later versions incorporate SIMD instructions to accelerate vector mathematics operations, enabling efficient handling of array processing and numerical computations in JavaScript.[40] To maintain correctness, the JIT includes deoptimization mechanisms, where execution bails out to the interpreter if runtime conditions violate compilation assumptions, such as unexpected type changes or overflows. Upon bailout, the engine invalidates the optimized code, reverts to interpretation for re-profiling, and may trigger recompilation with updated assumptions; repeated bailouts can lead to disabling optimizations for the affected code path.[36]Key Features
Language Extensions and Support
Chakra, as the JavaScript engine powering JScript in Internet Explorer 9 and later, included support for several JScript-specific APIs designed for integration with the Windows ecosystem. Thewindow.external object enabled interactions with Internet Explorer-specific features, such as accessing external application services or browser extensions. Similarly, the ActiveXObject constructor facilitated COM automation, allowing scripts to instantiate and manipulate ActiveX controls for tasks like file access or database connectivity in legacy web applications. These APIs were retained in Chakra for Internet Explorer 11 to maintain compatibility with existing enterprise and intranet sites reliant on Windows-specific scripting.
In terms of ECMAScript 6 (ES6) and later features, Chakra provided progressive support across its implementations. Internet Explorer 11's Chakra offered partial ES6 compatibility, including features such as let and const declarations, default parameters, and rest parameters, but lacked support for classes, modules, generators, and many other ES6 features. By contrast, the Chakra engine in Microsoft Edge delivered comprehensive ES6+ implementation, encompassing modules for modular code organization, enhanced classes with inheritance, and generators for asynchronous-like control flow without requiring full async/await. This evolution aligned Chakra with modern web standards while building on its ES5 baseline.[3]
Chakra incorporated debugging aids to enhance developer productivity, particularly through integration with browser tools. Source maps were supported to map minified or transpiled code back to original sources, enabling accurate breakpoint setting and stack trace inspection in the F12 developer tools. Enhancements to the console API, such as improved formatting for objects and arrays, along with support for console.table() and console.group(), facilitated more effective logging and debugging workflows in both Internet Explorer and Edge environments.
Security features in Chakra emphasized safe script execution, including compliance with Content Security Policy (CSP) to restrict script sources and mitigate cross-site scripting risks. Sandboxing mechanisms allowed for isolated execution of untrusted scripts, using runtime constraints in the JavaScript Runtime (JSRT) APIs to limit access to host resources and prevent unauthorized operations.
For backward compatibility, Chakra supported a legacy JScript 5.6 mode to accommodate older Internet Explorer sites developed for earlier versions like IE5.5, where scripts could opt into modern parsing via directives while emulating classic behaviors such as variable scoping and error handling. This mode, activated through document compatibility directives or Active Scripting host configurations, ensured seamless operation of legacy code without breaking existing deployments.[3]
