Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(client): Replace chalk with kleur/color #18900

Merged
merged 6 commits into from
Apr 25, 2023
Merged

perf(client): Replace chalk with kleur/color #18900

merged 6 commits into from
Apr 25, 2023

Conversation

SevInf
Copy link
Contributor

@SevInf SevInf commented Apr 24, 2023

Signgicantly reduces bundle size (kleur is <1KB in size, which reduces library runtime size from 280K to 255K) and
improves require(runtime) performance by 5-10ms:

image

Few implementation notes:

  • kleur is limited to 16 colors, in particular, *Bright versions of the colors are not supported. I replaced them with non-bright versions, which still look ok in the several places I've checked, and IMHO, is a fair price to pay for size/startup performance improvements. If you disagree - let me know.
  • migrate and cli technically did not need to migrate, but since we moving and sharing code between different packages from time to time, I've decided it would be better if we handle colors the same way everywhere and went for complete chalk removal.

Close prisma/client-planning#341

@SevInf SevInf added this to the 4.14.0 milestone Apr 24, 2023
Signgicantly reduces bundle size (from 280K to 255K) and
improves `require(runtime)` performance by 5-10ms.
@codspeed-hq
Copy link

codspeed-hq bot commented Apr 24, 2023

CodSpeed Performance Report

Merging #18900 perf/no-chalk (1117dd2) will not alter performances.

Summary

🔥 0 improvements
❌ 0 regressions
✅ 3 untouched benchmarks

🆕 0 new benchmarks
⁉️ 0 dropped benchmarks

@SevInf SevInf marked this pull request as ready for review April 24, 2023 13:56
@SevInf SevInf requested a review from a team April 24, 2023 13:56
@SevInf SevInf requested review from aqrln and removed request for a team April 24, 2023 13:56
Copy link
Member

@aqrln aqrln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Halfway so far, I'll continue reviewing further. Thanks for doing this!

…t.ts

Co-authored-by: Alexey Orlenko <alex@aqrln.net>
Copy link
Contributor

@Jolg42 Jolg42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say that I read every line, but at least most 😅
Looks great 🙌🏼

@SevInf SevInf merged commit 56672be into main Apr 25, 2023
51 of 53 checks passed
@SevInf SevInf deleted the perf/no-chalk branch April 25, 2023 12:16

export class DbCommand implements Command {
public static new(cmds: Commands): DbCommand {
return new DbCommand(cmds)
}

private static help = format(`
${process.platform === 'win32' ? '' : chalk.bold('🏋️ ')}Manage your database schema and lifecycle during development.
${process.platform === 'win32' ? '' : bold('🏋️ ')}Manage your database schema and lifecycle during development.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bold with emoji probably doesn't have any visible effect

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although not sure, maybe it might depending on the font

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's quite a lot of these bold emojis as far as I see, maybe there was some intention behind it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my guess would be, they used to be some plain unicode symbol for which bold made sense and got changed to emoji later

import terminalLink from 'terminal-link'

export function link(url): string {
return terminalLink(url, url, {
fallback: (url) => chalk.underline(url),
fallback: (url) => underline(url),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
fallback: (url) => underline(url),
fallback: underline,

(feel free to ignore though)

SevInf added a commit that referenced this pull request May 3, 2023
Address some of the feedback added to #18900 after it got merged
SevInf added a commit that referenced this pull request May 3, 2023
Address some of the feedback added to #18900 after it got merged
SevInf added a commit that referenced this pull request May 3, 2023
Address some of the feedback added to #18900 after it got merged
SevInf added a commit that referenced this pull request May 3, 2023
Address some of the feedback added to #18900 after it got merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants