unjs/consola

Printing a too-long-line causes 100% CPU workloads

kikuchan opened this issue · 0 comments

Environment

Consola v3.2.3

Node v20.7.0 / v18.17.1
Deno v1.36.4

Reproduction

import { consola } from 'consola';

consola.log('x'.repeat(200000));

Describe the bug

Printing a too-long-line causes 100% CPU workloads because of the high cost of Intl.Segmenter in string-width used by FancyReporter.

function stringWidth(str: string) {
// https://github.com/unjs/consola/issues/204
if (!Intl.Segmenter) {
return stripAnsi(str).length;
}
return _stringWidth(str);
}

https://github.com/sindresorhus/string-width/blob/f6e70c4c8de68ea2797a8765f1c7350ef0929a83/index.js#L27

Additional context

This could be a bug or a specification of string-width, but it is problematic when used as a part of logger.

on Bun 1.0.0, it is safe by the way. (I don't know whether its Intl.Segmenter is fully functional)

Logs

No response