Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Zig 日报】 2024-03-13 全新设计的文档系统 #102

Open
jiacai2050 opened this issue Mar 13, 2024 · 0 comments
Open

【Zig 日报】 2024-03-13 全新设计的文档系统 #102

jiacai2050 opened this issue Mar 13, 2024 · 0 comments

Comments

@jiacai2050
Copy link
Member

jiacai2050 commented Mar 13, 2024

Andrew 在这个 PR 里重构了现有的文档系统 Autodoc,之前的实现问题很多。老的实现:

  5987 src/Autodoc.zig
   435 src/autodoc/render_source.zig
 10270 lib/docs/commonmark.js
  1245 lib/docs/index.html
  5242 lib/docs/main.js
  2146 lib/docs/ziglexer.js
 25325 total

编译之后的文件

272K commonmark.js
3.8M data-astNodes.js
360K data-calls.js
767K data-comptimeExprs.js
2.2M data-decls.js
896K data-exprs.js
 13K data-files.js
  45 data-guideSections.js
 129 data-modules.js
  15 data-rootMod.js
 294 data-typeKinds.js
3.2M data-types.js
 38K index.html
158K main.js
 36M src/ (470 .zig.html files)
 78K ziglexer.js

改进后的实现:

   942 lib/docs/main.js
   403 lib/docs/index.html
   933 lib/docs/wasm/markdown.zig
   226 lib/docs/wasm/Decl.zig
  1500 lib/docs/wasm/markdown/Parser.zig
   254 lib/docs/wasm/markdown/renderer.zig
   192 lib/docs/wasm/markdown/Document.zig
   941 lib/docs/wasm/main.zig
  1038 lib/docs/wasm/Walk.zig
  6630 total

编译后的文件:

 12K index.html
 32K main.js
192K main.wasm
 12M sources.tar

一些大的改进点:

  • 很多功能重复的文件,最夸张的是 lib/docs/ziglexer.js ,它是用 JS 实现的 Zig 的解析器,其实 Zig 已经在标准库中暴露解析相关 API,通过 wasm 就可以调用
  • 功能更强,因为新设计方案不再处理 ZIR,而是直接处理源文件,这意味着它拥有100% 的信息,不需要向后拼凑任何东西。
  • sources.tar 文件经 HTTP 层解压后,直接进入 wasm 模块的内存。使用 std.tar 对 tar 文件进行解析,并对源文件进行就地解析,同时在哈希表中添加一些额外的计算。虽然可以通过 Worker 来加快解析速度,但单线程的解析速度已经非常快,因此这并不是非常有必要。

下面是 zig-curl 这个项目文档的前后对比:

之前

SCR-20240313-rslt

之后

SCR-20240313-rsio

很明显,层次感更好了。

快来体验最新的文档系统吧:https://ziglang.org/documentation/master/std/

PS:希望 Loris Cro 不要生气 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant