leaks when using primitives; fixable with WeakRef

オープン
#8 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
data

調査の方向性

まず Tuple と UniversalWeakMap の実装を見つけ、次に Tuple(primitive) が親ノードをどのように作成して保持するかを追跡します。現在の強参照と、提案されている WeakRef、FinalizationRegistry、グローバルな WeakMap を使うアプローチを比較します。完了条件は、さまざまなプリミティブのタプルを含め、ガベージコレクション後にタプルとそのマップがメモリを保持しなくなることです。

索引モデルが issue の本文から書いたものです。

説明

The description claims "no leaks", but if you do Tuple(primitive), that creates a UniversalWeakMap which can never be garbage collected. If you're creating a lot of tuples with a lot of different primitives, that can be a problem.

Now that we have WeakRef and FinalizationRegistry, I'm pretty sure it's possible to do better, so that there's actually no leaks: that is, no matter how many tuples you create and how you create them, once they've all been GC'd you're guaranteed that no additional memory is held.

The necessary changes are:

  1. When set(key, value) is called on a UniversalWeakMap, store a WeakRef to value instead of storing value directly, and register value in a FinalizationRegistry so that when it is collected key is cleared from the map.
  2. Use a global WeakMap to store a map from each created tuple to all of its parent nodes.

Then the only strong references to UniversalWeakMap objects (except the root) are from the tuples stored in those maps. Once all the tuples stored in a given UniversalWeakMap are GC'd, it can be GC'd as well.

The only caveat with this approach is if the user uses a tuple as a key in a weak collection. In that case the tuple can still get collected even if it was only holding primitives, which might be surprising. But that's unavoidable if avoiding leaks.

主要言語
JavaScript
スター
38
フォーク
3
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

benjamn/immutable-tuple のほかの issue

benjamn/immutable-tuple の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。