以下の内容はhttps://let.blog.jp/tag/V8より取得しました。


V8 の harmony フラグの一覧
久々に V8 の --harmony-xxx のフラグを使ったのですが 今って harmony フラグってどれくらいあるんでしょうか
ググって出てくるものって過去の時点のものばかりなので参考にできないです

Node.js だと --v8-options で V8 のオプション一覧が出せるので ここから harmony を含むものを取り出します

root@c3872dcf640f:/# node -v
v21.6.0

root@c3872dcf640f:/# node -p process.versions.v8
11.8.172.17-node.19

root@c3872dcf640f:/# node --v8-options | grep harmony
--harmony (enable all completed harmony features)
type: bool default: --no-harmony
--harmony-shipping (enable all shipped harmony features)
type: bool default: --harmony-shipping
--harmony-import-attributes (enable "harmony import attributes" (in progress / experimental))
type: bool default: --harmony-import-attributes
--harmony-weak-refs-with-cleanup-some (enable "harmony weak references with FinalizationRegistry.prototype.cleanupSome" (in progress / experimental))
type: bool default: --no-harmony-weak-refs-with-cleanup-some
--harmony-temporal (enable "Temporal" (in progress / experimental))
type: bool default: --no-harmony-temporal
--harmony-shadow-realm (enable "harmony ShadowRealm" (in progress / experimental))
type: bool default: --no-harmony-shadow-realm
--harmony-struct (enable "harmony structs, shared structs, and shared arrays" (in progress / experimental))
type: bool default: --no-harmony-struct
--harmony-array-from-async (enable "harmony Array.fromAsync" (in progress / experimental))
type: bool default: --no-harmony-array-from-async
--harmony-intl-best-fit-matcher (enable "Intl BestFitMatcher" (in progress / experimental))
type: bool default: --no-harmony-intl-best-fit-matcher
--harmony-remove-intl-locale-info-getters (enable "Remove Obsoleted Intl Locale Info getters" (in progress / experimental))
type: bool default: --no-harmony-remove-intl-locale-info-getters
--harmony-intl-locale-info-func (enable "Intl Locale Info API as functions" (in progress / experimental))
type: bool default: --no-harmony-intl-locale-info-func
--harmony-intl-duration-format (enable "Intl DurationFormat API" (in progress / experimental))
type: bool default: --no-harmony-intl-duration-format
--harmony-set-methods (enable "harmony Set Methods")
type: bool default: --no-harmony-set-methods
--harmony-iterator-helpers (enable "JavaScript iterator helpers")
type: bool default: --no-harmony-iterator-helpers
--harmony-import-assertions (enable "harmony import assertions")
type: bool default: --harmony-import-assertions
--harmony-change-array-by-copy (enable "harmony change-Array-by-copy")
type: bool default: --harmony-change-array-by-copy
--harmony-rab-gsab (enable "harmony ResizableArrayBuffer / GrowableSharedArrayBuffer")
type: bool default: --harmony-rab-gsab
--harmony-regexp-unicode-sets (enable "harmony RegExp Unicode Sets")
type: bool default: --harmony-regexp-unicode-sets
--harmony-json-parse-with-source (enable "harmony json parse with source")
type: bool default: --harmony-json-parse-with-source
--harmony-rab-gsab-transfer (enable "harmony ArrayBuffer.transfer")
type: bool default: --harmony-rab-gsab-transfer
--harmony-array-grouping (enable "harmony array grouping")
type: bool default: --harmony-array-grouping

結構多めですね
ただ array-grouping や change-array-by-copy など すでにリリース済み機能も入ってるようです
出たばかりはまだ安定してないかもなので無効にするためなんでしょうか

デフォルトで有効かどうかは default のところが --no- ではじまるかでわかります
--no- で始まってれば無効です
in progress / experimental とは一致してないみたいです

V8 のソースコード的にはこの辺で定義されてるようでした

https://github.com/v8/v8/blob/12.2.280/src/flags/flag-definitions.h#L247
https://github.com/v8/v8/blob/12.2.280/src/flags/flag-definitions.h#L292
PL/V8 みつけた
sql ファイルでちょっと複雑な処理したいけど SQL でできるの?
→ぐぐったらできそうなコードがあるけどどう動かすのか調べてみたら PL/pgSQL

DO statement で使えるぽいけどあんまり使いたくない
他になにかないのかな
→PL/Python があった

良さげだけど Python のインストールとか準備面倒そう
Python あるなら JavaScript もあるんじゃないの?
PL/V8 があった

11 時点のドキュメントだと Python や Perl は PL/* に載ってるけど V8 はない
まだマイナーどころかも

JavaScript でやるなら node-postgres を使って Node.js でやればいいんだけど ちょっと使った感じではそれらを準備するより楽に使える
Node.js で使うとコネクションとか非同期クエリ実行とか色々考えるところや面倒なところあり
PL/V8 だと DB 内で処理されるわけだからクエリは同期的だし 面倒な準備も不要
psql で接続して SELECT や INSERT 文の代わりに JavaScript 書く感じ
普通に Node.js でやるよりはいいかも

それに その場での実行だけじゃなくて関数も作れる
複雑な条件の SQL 処理は全部事前に関数を作っておいて クライアントでは関数呼び出すだけで済むようにすると便利そう
複数回 SQL を実行して結果をまとめたりするのを Node.js でやるよりは PostgreSQL 側でやってしまったほうが無駄な通信も減らせる
PostgreSQL は JSON でデータ返せるから JavaScript で処理した結果を返すのにも向いてる
なにより SQL ではやりたいことの関数名と引数だけで済むほうが Node.js 側がスッキリする

ただ PL/V8 内の SQL の実行は関数呼び出しになるので if 文で分岐や変数埋め込みしたい程度ならあんまり見やすくならない
SQL を直接書ける PL/pgSQL のほうが見やすくかけそう
クエリ結果のデータを処理する部分で JavaScript 使いたいくらいじゃないとメリットは少ないかも
v8-compile-cache
yarn のコード見てたら v8-compile-cache っていうのを使ってるみたい
https://github.com/yarnpkg/yarn/blob/v1.19.2/bin/yarn.js#L15

https://github.com/zertosh/v8-compile-cache
https://nodejs.org/api/vm.html#vm_vm_executing_javascript

パースとコンパイルした状態のキャッシュを保存しておいてそれを読み込むことでパースとコンパイル分の時間が短縮される……のかな
サーバみたいな常駐系と違って yarn みたいななにかしてすぐ終了するコマンドラインツールだと コマンド実行のたびにモジュールロードしてコンパイルしてとなって時間かかるから そこを省略できるなら効率良さそう
モジュールが多くて重いコマンド系ツール作るときに使ってみるのありかも



以上の内容はhttps://let.blog.jp/tag/V8より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14