2023 年的德诺
Deno in 2023

原始链接: https://deno.com/blog/deno-in-2023

In terms of improving performance and efficiency for web server setups, Deno's 德诺.serve() 功能引入并简化了 Web 服务器的创建,节省了开发人员的时间和精力。 此外,在将使用基本节点项目的“Hello, World”服务器设置与使用 denoserve() 创建的服务器设置进行比较时,由于核心库和事件循环机制中的针对性优化而带来的性能提升是显而易见的。 具体来说,当使用 wrk 基准套件进行测试时,deno 服务 http 请求的 HTTP 吞吐量几乎翻倍,超过了同类节点项目实现的平均速率。 In contrast, deno running identical "hello, world" node setups demonstrated a roughly 50% decrease in request completion times. 总体而言,HTTP 吞吐量的性能提升几乎达到了 6 倍,相当于每个请求大约 590 毫秒(仅考虑 HTTP 层)。 事件循环机制的增益还显示出平均响应时间和中值请求处理时间显着减少,大约为同类节点实现通常所需时间的一半。 此外,Deno 的改进不仅仅局限于 Node 项目,由于增强了与 Node 和 npm 的兼容性,还扩展到其他流行的 npm 包。 With 并行--不稳定-byonm 并行--不稳定-马虎-导入 并行--不稳定-不安全-原型 存在标志后,Deno 能够以比使用 Node 的传统安装快得多的速度执行专门为 Node 编写的 npm 包。 此外,值得承认的是,Deno 的性能提升似乎不会对 Web 服务器内存消耗或运行期间的延迟产生不利影响。 因此,无论是实现简单的静态站点结构,还是复杂而复杂的后端 Web 应用程序架构,Deno 都是创建快速响应的 Web 服务器配置的出色解决方案。”

关于 Deno 权限系统的讨论强调了 Deno 与传统 Node 使用相比的一个潜在缺点。 虽然 Deno 提供了更好的安全选项,例如限制网络请求或允许特定环境访问,但这些好处的代价是可能会减慢开发周期以及增加设置和管理环境的难度。 此外,虽然 Deno 提供了多种授予权限的方法,但人们担心,在 macOS 和 Windows 等非 Linux 环境中,开销和复杂性可能会增加,特别是考虑到使用包装器脚本来处理更复杂的权限方案。 最终,必须考虑 Deno 增加的安全措施之间的权衡以及特定用例的要求。 然而,值得注意的是,即使没有标志,Deno 也会提示用户允许某些访问选项,从而避免静默失败。
相关文章

原文

In 2023, Deno shifted into high gear with respect to Node/npm compatibility and performance work, while continuing to move towards our goal of radically simplifying web development. Here’s a summary of what changed in 2023:

Let’s dive deeper into the changes below.

Enhanced Compatibility with Node and npm

In a significant move toward ecosystem harmony, Deno expanded its capabilities in 2023 by incorporating built-in Node modules, such as node:fs and node:child_process, accessible through the node: specifier. This addition builds on the native npm support introduced in late 2022, using the npm: specifier, further bridging the gap between Deno and the Node ecosystem. As of now, Deno boasts partial or full support for 38 of the 42 Node built-in APIs, marking a substantial stride in compatibility.

To facilitate a smoother transition from Node to Deno, we introduced several new features:

These enhancements are particularly useful for developers looking to run existing Node projects in Deno without extensive modifications.

A notable advancement in the past year was the stabilization of the Node-API. This development eliminates the need for the --unstable flag when utilizing npm packages dependent on Node-API, thereby broadening the range of supported npm packages and streamlining the integration process.

Simpler, faster web server with Deno.serve()

We’ve significantly streamlined web server creation in Deno by introducing and stabilizing the Deno.serve() function, allowing developers to launch a server with minimal code:

Deno.serve((req) => new Response("Hello, world"));

This enhancement is part of our ongoing commitment to simplify development processes and reduce the need for extensive boilerplate code. The Deno.serve() function embodies this philosophy, enabling efficient and concise server setup.

Performance has seen substantial improvements through targeted optimizations in the core libraries and the event loop mechanism. In benchmark tests using a basic “Hello, world” server setup, Deno’s HTTP throughput has seen remarkable gains, nearly doubling since late 2023. When compared to a similar Node.js server, Deno now demonstrates a ~61% increase in throughput, alongside notable enhancements in tail latency and memory efficiency.

HTTP benchmark in requests per second

Run on bare metal 8 core, 64GB ram, Intel Xeon E-2378G with `wrk -d 10s`

These advancements are not limited to Deno-specific projects; they extend to modules and applications utilizing the node:http module, thanks to Deno.serve’s underlying architecture.

A key factor in these performance gains is the improved integration of Deno’s HTTP interfaces with the Hyper and Reqwest libraries. This integration has minimized unnecessary data allocation and duplication across different layers of the Deno runtime.

Furthermore, we’ve optimized the Deno event loop, responsible for managing asynchronous operations and resource monitoring, to reduce overhead and enhance the runtime’s overall efficiency. These collective improvements underscore our dedication to providing a robust, high-performance environment for web development.

More flexible deno.json

At Deno, we stand by the principle of zero-configuration programming, particularly valuing the simplicity of single-file programs, even for those written in TypeScript. Recognizing that larger projects often demand more sophisticated setups, we’ve continuously improved our optional deno.json configuration file to meet these complex needs without sacrificing ease of use:

  • Streamlined Configuration: We’ve transformed deno.json to double as an import map, effectively reducing the need for separate configuration files and simplifying project setups. Learn more about import maps.
  • Enhanced Formatting Options: deno fmt now supports semicolons, offering more flexibility in code styling to accommodate diverse developer preferences.
  • Node and npm Compatibility: Integration with package.json enhances compatibility, making it easier for projects to transition between Node and Deno environments. See how we improved compatibility.
  • Simplified Configuration Structure: We’ve flattened the deno.json structure, making it more intuitive and easier to navigate for developers. Discover the simpler structure.
  • Glob Support: The introduction of glob patterns in deno.json allows for more precise control over file and directory inclusion or exclusion in various operations such as formatting, linting, and testing. Explore glob support details.

These enhancements are part of our ongoing commitment to making Deno not only powerful and versatile for large-scale applications but also simple and accessible for smaller projects.

Smoother development experience with LSP

Deno’s Language Server Protocol (LSP) integration elevates the development experience within editors and IDEs, offering robust features like precise go-to-definition, comprehensive IntelliSense, and seamless code formatting for TypeScript projects. This year, we’ve dedicated significant effort to enhance the LSP, making coding in Deno smoother and more intuitive:

  • Extended Auto-Complete: Now includes support for npm: and node: specifiers, streamlining the use of Node modules within Deno.
  • VSCode Extension Activation: The Deno VSCode extension is now triggered automatically when a deno.json file is detected in your project, ensuring immediate access to Deno’s powerful tooling.
  • Intelligent Import Management: Imports in TypeScript and JavaScript files are now updated automatically when files are renamed, maintaining code consistency and reducing manual refactoring.
  • Efficient Document Pre-Loading: Ensures features like “find references” work seamlessly across all files in a project, enhancing code navigation and understanding.

To fully leverage these improvements, try the Deno extension for Visual Studio Code, designed to integrate these enhancements directly into your development workflow.

WebGPU

Deno has now integrated WebGPU, a cutting-edge technology that empowers developers to harness the power of GPU hardware directly with JavaScript. This high-performance, low-level interface is designed for a wide range of applications, from graphics rendering to data analysis, and machine learning, all within the familiar environment of web-standard JavaScript.

After a year of dedicated development, WebGPU is accessible in Deno behind the --unstable-webgpu flag, marking a significant milestone in expanding the capabilities of Deno applications. This feature is especially promising for developers looking to push the boundaries of what’s possible with JavaScript in areas requiring intense computational power.

We are also actively developing features to enable WebGPU for rendering in native GUI windows, further broadening the potential use cases for Deno developers. Stay updated on this feature’s progress.

To explore practical applications and see WebGPU in action within Deno, visit our WebGPU examples repository, which provides a variety of sample projects and code snippets.

Jupyter notebooks

Jupyter, the open source notebook tool, added support for JavaScript and TypeScript using Deno. This means data science, visualization, and more can all be done using modern JavaScript and TypeScript and web standards APIs.

Here’s an example of grabbing data with fetch and visualizing it with observablehq/plot:

A scatter plot in Jupyter notebooks using TypeScript with Deno

Jupyter support has also enabled building generative AI/ML models using JavaScript and TypeScript, as Andrew Ng and DeepLearning.AI have developed a generative AI course on building LLM Apps with LangChain.js that uses Deno.

Notable open source rust crates

Deno’s surface area touches a wide range of open source projects, which we eagerly contribute to in order to expand Deno’s feature set and optimize performance. This year, we released a few Rust crates that developers might find useful independently of Deno itself:

  • rustls-tokio-stream a Rust crate that replaces tokio-rustls adding more advanced features like supporting duplex I/O via tokio::io::split. Critically it does not require either read or write polling to perform handshakes.
  • fastwebsockets is a minimal, fast WebSocket server implementation that sits behind Deno’s WebSocket implementation. It completely passes the Autobahn TestSuite and fuzzed with LLVM’s libfuzzer. You can use it as a raw websocket frame parser and deal with spec compliance yourself, or you can use it as a full-fledged websocket server.
  • monch is a parser inspired by nom, but specifically for strings and with some additional combinators we use in Deno. It backs deno_task_shell.
  • deno_task_shell is a cross platform shell implementation that helps deno task run across windows and unix. Think of it as a more advanced version of the common Node.js utility cross-env.

Fresh

We continued to make Fresh, Deno’s modern full stack web framework that sends zero client-side JavaScript by default, easier to use and more performant.

We’ve got a lot planned for Fresh in 2024, such as view transitions, hot module reloading, and faster JSX transforms.

Expanding Deno’s cloud business

Though we’ve covered the big updates from our open source projects, the overall Deno picture would be incomplete without mentioning developments on the commercial side.

Though Deno Subhosting has been around for a while powering Netlify’s edge functions and Deco.cx’s customer’s e-commerce stores, this year we made it self-service so that anyone can deploy and run their user’s code programmatically via our Subhosting API for free. It’s built to run third-party, untrusted code securely, as it’s designed from the ground up for maximum tenant isolation. (Not sure what to use Deno Subhosting API for? Check out this tutorial on how to build your own cloud IDE.)

We’re made strides towards our vision of radically simplifying web development with the launch of cloud primitives: Deno KV, Queues, and Cron. They’re built right into the runtime so you can get setup without juggling API keys or futzing with config:

const kv = await Deno.openKv();

These cloud primitives seamlessly become globally distributed services when you use Deno Deploy, optimizing your servers and applications for performance.

We’ve also broadened access to Deno KV by turning it into its own open sourced binary, added support to remotely connect to any Deno KV instance, made it accessible in Node/npm via our official Deno KV npm module, as well as adding support for continuous replication with point-in-time recovery to S3 and GCS.

We’ve got some big plans to simplify cloud development even further with more features and new primitives, so stay tuned.

Deno 2 👀

We’re preparing for Deno 2, which will offer improved compatibility with Node and npm, by providing a migration guide to ensure a smooth transition. Alongside an improved runtime, we also have some exciting announcements around managing and optimizing dependencies for your projects. Stay tuned in the coming weeks for a more detailed roadmap of what’s to come. If you want a sneak peak - look here.


Don’t miss any updates! Follow us on Twitter.

联系我们 contact @ memedata.com