Closed Vasile-Peste closed 1 year ago
There isn't really an opinion split on the folks who are working/proposing this improvement, as noted in the FAQ:
Could this proposal enable runtimes to optimize performance based on type hints?
Whilst it is possible to theorize runtime optimizations driven by statically declared types, the proposal authors are not aware of successful experiments in JavaScript that meaningfully beat dynamic type-driven JIT optimization.
The proposed type syntax has no defined semantics and so is opaque to the runtimes. It is equivalent to asking "Could a runtime use / comments / to optimize performance?" To which the answer is: almost certainly not - at least not in a standard way. Therefore this proposal alone does not directly offer new opportunities for performance improvements.
It is explicitly a non-goal of this proposal to improve the performance of JavaScript.
It's not about the authors opinion but the community, and we can see this division just from the issues, you don't agree?
Please note that runtime checking was effectively blocked at the March 2023 plenary. See notes
excerpt from the notes:
Apparently the community opinion about this proposal is divided between Claims that it's not necessary if it has no runtime benefits Claims runtime benefits are not really essential
Logically this means that if we add runtime benefits "everyone" should be satisfied, that's why I'm here proposing to NOT TREAT TYPES just as comments
While JavaScript is traditionally considered a dynamically-typed language, the addition of optional types could introduce several advantages, including improved performance and enhanced tooling capabilities.
Runtime performance is a crucial consideration in any programming language, and optional types can contribute to better runtime performance in JavaScript. By providing type annotations, the JavaScript engine, such as V8, can leverage the information to optimize code execution. With type information, the engine can perform more efficient optimizations, such as type-based inline caching, specialized code generation, and elimination of unnecessary runtime checks.
The V8 JavaScript engine, which powers popular browsers like Chrome and Node.js, has a team of skilled engineers who continuously work on enhancing JavaScript performance. While I don't have access to the specific opinions of V8 engineers on this topic, it is worth noting that the V8 team has already made significant efforts to improve JavaScript performance through various optimization techniques. Introducing optional types could align with their ongoing mission to optimize JavaScript execution.
I would like to add: as JavaScript has evolved from being primarily web-centric to a versatile language used in various fields such as server-side development, desktop applications, mobile apps, and even IoT devices! Runtime benefits become increasingly necessary. In these diverse contexts, performance optimizations enabled by optional types can have a significant impact. Faster runtime execution leads to improved user experiences, and more efficient resource utilization on constrained devices. Additionally, robust type systems aid in the development of large-scale applications, critical software, and collaborative projects.
In addition to performance benefits, and to align with this proposal, adding types to JavaScript would greatly enhance the development experience and enable more powerful tooling. With type annotations, static type checkers and IDEs can provide developers with better autocompletion, code navigation, and error detection at compile-time. These tools can catch potential bugs early in the development process, reducing the debugging effort and improving code quality.
While some argue that runtime benefits are not crucial for optional types, it's important to recognize that runtime performance improvements and enhanced tooling capabilities go hand in hand. By leveraging type information at runtime, JavaScript engines can optimize code execution, leading to faster and more efficient applications. Additionally, the availability of types enables a wide range of static analysis tools and IDE integrations, which significantly enhance the development experience and productivity of JavaScript developers.
It would be insightful to hear the opinion of V8 engineers and ECMAScript committee members to gain a more comprehensive understanding of their stance on the proposal and their considerations regarding the runtime benefits of adding types to JavaScript.