readFile in promises very slow

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, node.js
領域
performance

調査の方向性

まず、提供されている2つのベンチマークを Node.js v21.7.1 で実行し、fs/promises.readFile と util.promisify(fs.readFile) を比較してください。レポートで言及されている fs/promises と fs のエントリポイントを使ってパフォーマンスの差を調査してください。完了には、再現可能な説明と、期待される動作の確認が必要です。

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

説明

Version

v21.7.1

Platform

Darwin evgeniis.local 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:43 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

slow

const fs = require('fs/promises');

const start = Date.now();
let count = 0;
for (let i = 0; i < 10000; i++) {
	fs.readFile("./text.txt", { encoding: 'utf-8' })
		.then((data) => {
			if (data !== "Hello, world") throw 1;
			count++
			if (count === 10000) {
				console.log('time: ', Date.now() - start);
			}
		})
		.catch((err) => {
			throw 1
		})
}

fast

const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);

const start = Date.now();
let count = 0;
for (let i = 0; i < 10000; i++) {
	readFile("./text.txt", { encoding: 'utf-8' })
		.then((data) => {
			if (data !== "Hello, world") throw 1;
			count++
			if (count === 10000) {
				console.log('time: ', Date.now() - start);
			}
		})
		.catch((err) => {
			throw 1
		})
}
How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

The promise version is 2 times slower. My tests showed 200ms vs 100ms

Additional information

No response

主要言語
Shell
スター
399
フォーク
11
平均マージ
29分
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

nodejs/performance のほかの issue

nodejs/performance の issue をすべて見る

似ている issue

Shell/Bash の issue をもっと見る

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

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