manishearth

5 articles

← Back Live Monitor RSS Feed

零值甚至为负?(零拷贝#3)

Translated AI Summary eng
[AI 摘要] 介绍databake库,通过将数据序列化为Rust const代码实现零成本数据加载,完全避免反序列化步骤。
View content
<p><em>这是关于零拷贝反序列化有趣抽象的三部分系列的第三篇。这一部分将彻底消除反序列化步骤。第一部分是关于使其更易用,可在此<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-1-not-a-yoking-matter/">找到</a>;第二部分是关于使其适用于更多类型,可在此<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-2-zero-copy-all-the-things/">找到</a>。文章可以按任何顺序阅读,但只有第一篇解释了零拷贝反序列化<em>是什么</em>。</p> <blockquote> <p>当亚历山大看到自己作品的广度时,他哭了。因为再也没有拷贝可以归零了。</p> <p>——汉斯·格鲁伯,在设计了三个越来越疯狂的零拷贝crate之后</p> </blockquote> <p>本系列的<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-1-not-a-yoking-matter/">第一部分</a>试图回答“我们如何使零拷贝反序列化<em>更愉快</em>”这个问题,而<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-2-zero-copy-all-the-things/">第二部分</a>回答了“我们如何使零拷贝反序列化<em>更有用</em>?”。</p> <p>这更进一步,提出:“如果我们能完全避免反序列化会怎样?”。</p> <div class="discussion discussion-example"> <img class="bobblehead" width="60px" height="60px" title="Confused pion" alt="Speech bubble for character Confused pion" src="http://manishearth.github.io/images/pion-nought.png" /> …
Show original
<p><em>This is part 3 of a three-part series on interesting abstractions for zero-copy deserialization I’ve been working on over the last year. This part is about eliminating the deserialization step entirely. Part 1 is about making it more pleasant to work with and can be found <a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-1-not-a-yoking-matter/">here</a>; while Part 2 is about making it work for more types and can be found <a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-2-zero-copy-all-the-things/">here</a>. The posts can be read in any order, though only the first post contains an explanation of what zero-copy deserialization</em> is.</p> <blockquote> <p>And when Alexander saw the breadth of his work, he wept. For there were no more copies left to zero.</p> <p>—Hans Gruber, after designing three increasingly unhinged zero-copy crates</p> </blockquote> <p><a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-1-not-a-yoking-matter/">…
Read article Original

万物皆可零拷贝!(零拷贝 #2)

Translated AI Summary eng
[AI 摘要] 本文介绍了为Rust语言开发的zerovec crate,它通过ZeroVec和VarZeroVec类型,扩展了零拷贝反序列化对更复杂数据类型(如整数向量和字符串向量)的支持。
View content
<p><em>这是我关于零拷贝反序列化的一些有趣抽象概念的三部分系列文章的第二部分。第一部分是关于使其更易于使用,可以在<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-1-not-a-yoking-matter/">这里</a>找到;而第三部分是关于完全消除反序列化步骤,可以在<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-3-so-zero-its-dot-dot-dot-negative/">这里</a>找到。这些文章可以按任何顺序阅读,但只有第一篇包含了对什么是零拷贝反序列化的解释。</em></p> <h2 id="background">背景</h2> <p><em>本节与上一篇文章相同,如果您已经读过,可以跳过。</em></p> <p>在过去的一年半里,我一直全职参与<a href="https://github.com/unicode-org/icu4x">ICU4X</a>的工作,这是一个在Unicode联盟下由多家公司协作构建的新的国际化库。</p> <p>关于ICU4X我能说的很多,但为了聚焦一个核心价值主张:我们希望它在数据和代码方面都是<em>模块化的</em>。我们希望ICU4X能在嵌入式平台上使用,因为那里内存很宝贵。我们希望受下载大小限制的应用程序能够支持所有语言,而不是因为无法负担打包所有数据而只能选择少数几种流行语言。为此,我们希望数据加载是<em>快速的</em>且可插拔的。用户应该能够为他们的具体用例设计自己的数据加载策略。</p> <p>请注意,执行正确国际化的一个关键部分是<em>数据</em>。不同的区域设置<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>有不同的做法,所有关于这些的信息都需要有地方存储,最好不要放在代码里。你需要数据来说明特定区域设置如何格式化日期<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc…
Show original
<p><em>This is part 2 of a three-part series on interesting abstractions for zero-copy deserialization I’ve been working on over the last year. This part is about making zero-copy deserialization work for more types. Part 1 is about making it more pleasant to work with and can be found <a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-1-not-a-yoking-matter/">here</a>; while Part 3 is about eliminating the deserialization step entirely and can be found <a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-3-so-zero-its-dot-dot-dot-negative/">here</a>. The posts can be read in any order, though only the first post contains an explanation of what zero-copy deserialization</em> is.</p> <h2 id="background">Background</h2> <p><em>This section is the same as in the last article and can be skipped if you’ve read it</em></p> <p>For the past year and a half I’ve been working full time on <a href="https://github.com/unicode-org/icu4x">ICU4X</a>, a new internationalizati…
Read article Original

这不是玩笑(零拷贝系列 #1)

Translated AI Summary eng
[AI 摘要] 本文介绍了“yoke” crate,它通过自引用类型实现Rust零拷贝反序列化的生命周期擦除,使管理借用数据更便捷。
View content
<p><em>这是我过去一年一直在研究的零拷贝反序列化有趣抽象系列的三部分中的第一篇。本部分关注如何让零拷贝反序列化更易于使用。第二部分关注如何使其支持更多类型,可在此处找到<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-2-zero-copy-all-the-things/">链接</a>;第三部分则关注完全消除反序列化步骤,可在此处找到<a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-3-so-zero-its-dot-dot-dot-negative/">链接</a>。这些文章可以按任何顺序阅读,但本文包含对什么是零拷贝反序列化的解释。</em></p> <h2 id="background">背景</h2> <p>过去一年半,我一直在<a href="https://github.com/unicode-org/icu4x">ICU4X</a>上全职工作,这是一个在Unicode联盟下由多家公司合作构建的新国际化Rust库。</p> <p>关于ICU4X有很多可以说的,但聚焦一个核心价值主张:我们希望它在<em>数据和代码</em>上都是<em>模块化</em>的。我们希望ICU4X能在内存受限的嵌入式平台上使用。我们希望受下载大小限制的应用程序能够支持所有语言,而不是因为无法负担所有数据的打包而只能选择几种流行语言。作为其中的一部分,我们希望数据加载是<em>快速</em>且可插拔的。用户应该能够为他们的具体用例设计自己的数据加载策略。</p> <p>你看,执行正确国际化的一个关键部分是<em>数据</em>。不同的区域设置<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>做事方式不同,所有这些信息都需要一个地方存放,最好不是代码。你需要关于特定区域设置如何格式化日期<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc-noteref">2</a></sup…
Show original
<p><em>This is part 1 of a three-part series on interesting abstractions for zero-copy deserialization I’ve been working on over the last year. This part is about making zero-copy deserialization more pleasant to work with. Part 2 is about making it work for more types and can be found <a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-2-zero-copy-all-the-things/">here</a>; while Part 3 is about eliminating the deserialization step entirely and can be found <a href="http://manishearth.github.io/blog/2022/08/03/zero-copy-3-so-zero-its-dot-dot-dot-negative/">here</a>. The posts can be read in any order, though this post contains an explanation of what zero-copy deserialization</em> is.</p> <h2 id="background">Background</h2> <p>For the past year and a half I’ve been working full time on <a href="https://github.com/unicode-org/icu4x">ICU4X</a>, a new internationalization library in Rust being built under the Unicode Consortium as a collaboration between various companies.</…
Read article Original

Rust中安全追踪式GC设计之旅

Translated AI Summary eng
[AI 摘要] 本文探讨了在Rust中实现安全追踪式垃圾回收器的多种设计方案,分析了其挑战、共同点及不同实现案例。
View content
<p>自从我开始在 <a href="https://github.com/servo/servo">Servo</a> 的 JavaScript 层工作以来,我就一直在思考 Rust 中的垃圾回收(GC)。我曾 <a href="https://manishearth.github.io/blog/2015/09/01/designing-a-gc-in-rust/">设计过一个 GC 库</a>,<a href="https://manishearth.github.io/blog/2016/08/18/gc-support-in-rust-api-design/">研究过 Rust 本身的 GC 集成方案</a>,参与过 Servo 的 JS GC 集成工作,并帮助过其他一些 Rust GC 项目,如 <a href="https://github.com/asajeffrey/josephine">josephine</a> 和 <a href="https://github.com/kyren/gc-arena">gc-arena</a>。</p> <p>因此,我经常被卷入 GC 讨论。我喜欢谈论 GC——别误会——但我经常需要重复讲解相同的内容。我比较<a href="https://manishearth.github.io/blog/2018/08/26/why-i-enjoy-blogging/#blogging-lets-me-be-lazy">懒</a>,更希望能有一个地方,让人们可以快速了解 GC 设计的整体领域,然后再深入讨论特定设计的必要权衡。</p> <p>我需要说明的是,本文中的一些 GC 实现是实验性的或未被维护。本文的目标是将它们作为 <em>设计</em> 示例进行展示,而不一定是你可以直接使用的通用 crate,尽管其中一些也是可用的 crate。</p> <h3 id="a-note-on-terminology">关于术语的说明</h3> <p>关于 GC 的讨论常常被混淆的一点是,根据某些“GC”的定义,简单的引用计数(Reference Counting)<em>就是</em>一种 GC。学术界通常使用的 GC 定义广泛指任何形式的自动内存管理。然而,大多数熟悉“GC”一词的程序员通常将其等同于“Java、Go…
Show original
<p>I’ve been thinking about garbage collection in Rust for a long time, ever since I started working on <a href="https://github.com/servo/servo">Servo</a>’s JS layer. I’ve <a href="https://manishearth.github.io/blog/2015/09/01/designing-a-gc-in-rust/">designed a GC library</a>, <a href="https://manishearth.github.io/blog/2016/08/18/gc-support-in-rust-api-design/">worked on GC integration ideas for Rust itself</a>, worked on Servo’s JS GC integration, and helped out with a <a href="https://github.com/asajeffrey/josephine">couple</a> <a href="https://github.com/kyren/gc-arena">other</a> GC projects in Rust.</p> <p>As a result, I tend to get pulled into GC discussions fairly often. I enjoy talking about GCs – don’t get me wrong – but I often end up going over the same stuff. Being <a href="https://manishearth.github.io/blog/2018/08/26/why-i-enjoy-blogging/#blogging-lets-me-be-lazy">lazy</a> I’d much prefer to be able to refer people to a single place where they can get up to speed on the…
Read article Original

Rust中的Arena

Translated AI Summary eng
[AI 摘要] 本文介绍了Rust中Arena的用法、现有crate实现,并深入探讨了自引用Arena中涉及的酷炫生命周期效应。
View content
<p>最近关于Rust中的Arena有一些讨论,我想就这个话题写点东西。</p> <p>Arena并不是Rust中你通常会首先想到的东西,因此了解它的人较少;你通常只会在某些特定应用场景中看到它。通常,你可以通过引入一个crate来使用Arena,而无需额外使用<code class="language-plaintext highlighter-rouge">unsafe</code>,所以在Rust中不必对它特别担忧,而且了解它似乎很有用,特别是对于从Arena更常见的领域转向Rust的人来说。</p> <p>此外,当实现自引用Arena时,涉及一系列<em>非常酷的</em>生命周期效应,我认为之前还没有人写过相关内容。</p> <p>我写这篇文章主要是为了探讨那些酷的生命周期效应,但我觉得值得写一个对所有Rust程序员都有价值的通用介绍。如果你知道Arena是什么,只想了解酷的生命周期效应,可以直接跳到<a href="#implementing-a-self-referential-arena">实现自引用Arena的部分</a>。否则,请继续阅读。</p> <h2 id="whats-an-arena">什么是Arena?</h2> <p>Arena本质上是一种将预期具有相同生命周期的分配分组的方法。有时你需要为一个事件的生命周期分配一批对象,之后可以将它们全部丢弃。每次都调用系统分配器效率低下,更可取的做法是为你的对象<em>预分配</em>一批内存,在完成后一次性清理。</p> <p>广泛来说,你可能希望使用Arena有两个原因:</p> <p>首先,如前所述,你的主要目标可能是减少分配压力。例如,在游戏或应用程序中,可能有大量每帧需要分配然后丢弃的每帧对象。这在游戏开发中尤为常见,游戏开发者往往很关心分配器压力。使用Arena,可以轻松分配一个Arena,在每帧填充它,然后在帧结束后清理它。这还有缓存局部性的额外好处:你可以确保大多数每帧对象(可能比其他对象更频繁使用)在帧期间通常位于缓存中,因为它们是相邻分配的。</p> <p>另一个目标可能是你想编写自引用数据,比如一个可以一次性清理的复杂带循环图。例如,在编写编译器时,类型信息可能需要引用其他类型和其他数据,导致一个复杂的、可能是循环的类型图。一旦你计算了一个类型,你可能不需要…
Show original
<p>There’s been some discussion about arenas in Rust recently, and I thought I’d write about them.</p> <p>Arenas aren’t something you would typically reach for in Rust so fewer people know about them; you only really see them in applications for various niche use cases. Usually you can use an arena by pulling in a crate and not using additional <code class="language-plaintext highlighter-rouge">unsafe</code>, so there’s no need to be particularly skittish around them in Rust, and it seems like it would be useful knowledge, especially for people coming to Rust from fields where arenas are more common.</p> <p>Furthermore, there’s a set of <em>really cool</em> lifetime effects involved when implementing self-referential arenas, that I don’t think have been written about before.</p> <p>I’m mostly writing this to talk about the cool lifetime effects, but I figured it’s worth writing a general introduction that has something for all Rustaceans. If you know what arenas are and just want th…
Read article Original