GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [WIP] lib: optimize util.format() by bnoordhuis · Pull Request #215 · nodejs/node

Conversation

@bnoordhuis

@bnoordhuis bnoordhuis commented Dec 29, 2014

Copy link
Copy Markdown
Member

Optimize util.format() by parsing the format string and generating
specialized code on the fly, then caching the result in a LRU list.

This change is based on the observation that most applications that
log extensively, often have very skewed distributions of log patterns.
It's common to see top 10 or top 25 of popular patterns, followed by
a long (sometimes very long) tail of less popular patterns.

This is a work in progress: the common case is currently 2-25x faster
but the worst case - every pattern unique - is 4-5x slower.

WIP, soliciting comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bnoordhuis added 3 commits December 29, 2014 13:01
@bnoordhuis
lib: make linklist functions return useful values
6129721
Make a number of functions from require('_linklist') return the list or
the item just inserted.  Makes the API a little less unwieldy to use.
@bnoordhuis
benchmark: add util.format() benchmark
dffe15b
Add a simple (too simple!) benchmark for util.format().
@bnoordhuis
lib: optimize util.format()
5a74f84
Optimize util.format() by parsing the format string and generating
specialized code on the fly, then caching the result in a LRU list.

This change is based on the observation that most applications that
log extensively, often have very skewed distributions of log patterns.
It's common to see top 10 or top 25 of popular patterns, followed by
a long (sometimes very long) tail of less popular patterns.

This is a work in progress: the common case is currently 2-25x faster
but the worst case - every pattern unique - is 4-5x slower.
@rvagg rvagg mentioned this pull request Dec 30, 2014
File copyright policy #216
Closed
@piscisaureus piscisaureus closed this Dec 30, 2014
@piscisaureus piscisaureus reopened this Dec 30, 2014
bnoordhuis
bnoordhuis reviewed Jan 8, 2015
View reviewed changes
Comment thread lib/sprintf.js

@bnoordhuis bnoordhuis Jan 8, 2015

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Note to self: the generated code gets optimized as of https://codereview.chromium.org/821553003/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@trevnorris

trevnorris commented Jan 16, 2015

Copy link
Copy Markdown
Contributor

@bnoordhuis Side note, I've noticed that v8::Script::Compile() then v8::Script::Run() is 2x faster than new Function() from JS.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa

yosuke-furukawa commented Jan 16, 2015

Copy link
Copy Markdown
Member

I have benchmark results using template literals vs use "+" vs util.format.

Just FYI:
http://jsperf.com/template-literal-vs-string-plus/2

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@algesten

algesten commented Jan 16, 2015

Copy link
Copy Markdown

@yosuke-furukawa OMG! xD

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Jan 16, 2015

Copy link
Copy Markdown
Contributor

@yosuke-furukawa I'll have to refer you to http://mrale.ph/blog/2012/12/15/microbenchmarks-fairy-tale.html. The benchmark you show can be pretty much optimized out completely.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

charmander
charmander reviewed Jan 28, 2015
View reviewed changes
Comment thread lib/sprintf.js

@charmander charmander Jan 28, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Isn’t /[\\"\r\n\u2028\u2029]/g enough?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jan 28, 2015

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Now that you bring it up: probably not. With Harmony template strings being available now, the generated code is susceptible to template literal injection. I'll have to look at this again.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@charmander charmander Jun 26, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

/[\\"\r\n\u2028\u2029]/g is enough, and template strings don’t affect the parsing of double-quoted string literals.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tellnes

tellnes commented Feb 5, 2015

Copy link
Copy Markdown
Contributor

Since this introduces a new module (sprintf) which conflicts with a similar module on npm (npm.im/sprintf), should this be a major version bump. The sprintf should also probably be documented.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xaka
xaka reviewed Feb 5, 2015
View reviewed changes
Comment thread lib/sprintf.js

@xaka xaka Feb 5, 2015

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Did you want to use an internal argc instead of arguments.length for for loop as a cached value? Otherwise argc is unused.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mscdex mscdex added the util Issues and PRs related to the built-in util module. label Mar 22, 2015
@chrisdickinson

chrisdickinson commented Mar 25, 2015

Copy link
Copy Markdown
Contributor

Since #848 landed, we can probably introduce sprintf as an internal module.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisdickinson chrisdickinson added the land-on-master label Apr 17, 2015
@brendanashworth brendanashworth added the wip Issues and PRs that are still a work in progress. label May 11, 2015
@Qard

Qard commented Jun 26, 2015

Copy link
Copy Markdown
Member

Is anything happening with this at this point, or can it be closed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jun 26, 2015

Copy link
Copy Markdown
Member Author

I'll close it and revisit when I have time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis bnoordhuis closed this Jun 26, 2015
@estliberitas estliberitas mentioned this pull request Feb 17, 2016
util: possible way to speed up util.format() #5285
Closed
@ChALkeR ChALkeR added the performance Issues and PRs related to the performance of Node.js. label May 23, 2016
@snyk-bot snyk-bot mentioned this pull request Jan 8, 2020
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 timscharfenort/node#5
Open
@snyk-bot snyk-bot mentioned this pull request Jul 5, 2020
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 sitedata/node#3
Open
@snyk-bot snyk-bot mentioned this pull request Aug 11, 2020
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 radiumrasheed/node#3
Open
@snyk-bot snyk-bot mentioned this pull request Aug 27, 2020
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 aliceUnhinged613/node#5
Open
@snyk-bot snyk-bot mentioned this pull request Jan 10, 2021
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 ryan-ally/node#9
Merged
@trongham trongham mentioned this pull request Feb 25, 2021
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 trongham/node#9
Open
@snyk-bot snyk-bot mentioned this pull request Jun 28, 2021
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 ramonbrugman/node#13
Open
@snyk-bot snyk-bot mentioned this pull request Oct 10, 2022
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 lokera666/node#4
Open
This was referenced Feb 14, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 Dixiejane/node#5
Open
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 SanchitMahajan236/node#8
Closed
@snyk-bot snyk-bot mentioned this pull request Mar 15, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 davidmather/node#1
Open
@snyk-bot snyk-bot mentioned this pull request Mar 22, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 Bank4500/nodejs#5
Open
@snyk-bot snyk-bot mentioned this pull request Apr 24, 2023
[Snyk] Fix for 44 vulnerabilities aliscco/alisco-node#115
Open
@snyk-bot snyk-bot mentioned this pull request May 5, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 ashly1111111/node#14
Open
@nicholaschoi168 nicholaschoi168 mentioned this pull request May 16, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 nicholaschoi168/node#7
Open
This was referenced Jul 7, 2023
[Snyk] Fix for 21 vulnerabilities leonardoadame/node#65
Open
[Snyk] Fix for 22 vulnerabilities leonardoadame/node#75
Open
[Snyk] Fix for 22 vulnerabilities leonardoadame/node#89
Open
@pranathi-nallamilli pranathi-nallamilli mentioned this pull request Aug 5, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 pranathi-nallamilli/node#5
Open
@JCsomeShots JCsomeShots mentioned this pull request Sep 19, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 JCsomeShots/node#1
Open
@kingjay66 kingjay66 mentioned this pull request Oct 15, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 kingjay66/node#4
Open
@Jingyi090 Jingyi090 mentioned this pull request Nov 17, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 Jingyi090/node#1
Open
@nickfnblum nickfnblum mentioned this pull request Nov 21, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 nickfnblum/node#7
Open
@ashly1111111 ashly1111111 mentioned this pull request Nov 24, 2023
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 ashly1111111/node#69
Open
@aravindb26 aravindb26 mentioned this pull request Jan 4, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 aravindb26/node#1
Open
@CxsLucyfer CxsLucyfer mentioned this pull request Jan 29, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 CxsLucyfer/node#1
Open
@ahamedislam ahamedislam mentioned this pull request Feb 22, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 ahamedislam/node#1
Open
@DanyRay420 DanyRay420 mentioned this pull request Feb 24, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 DanyRay420/node#2
Open
@matrix-compute matrix-compute mentioned this pull request Mar 28, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 matrix-compute/node.js#2
Open
@ashly1111111 ashly1111111 mentioned this pull request Mar 29, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 ashly1111111/node#94
Open
@lairortega lairortega mentioned this pull request Apr 14, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 lairortega/node#1
Open
@yaseenaljamal yaseenaljamal mentioned this pull request Apr 25, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 yaseenaljamal/node#5
Open
@dannybrown13 dannybrown13 mentioned this pull request May 7, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 dannybrown13/node#93
Open
@CharliesAngel1 CharliesAngel1 mentioned this pull request May 7, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 CharliesAngel1/node#14
Open
@snyk-io snyk-io Bot mentioned this pull request May 21, 2024
[Snyk] Upgrade rollup-plugin-node-resolve from 4.0.0 to 4.2.4 Hawthorne001/node2#2
Open
syg pushed a commit to syg/node that referenced this pull request May 5, 2025
@rmahdav
deps: update simdutf to 6.4.0 (nodejs#215)
bf39ccb
bakkot pushed a commit to bakkot/node that referenced this pull request May 11, 2026
@rmahdav pthier
deps: update simdutf to 6.4.0 (nodejs#215)
5885d5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

performance Issues and PRs related to the performance of Node.js. util Issues and PRs related to the built-in util module. wip Issues and PRs that are still a work in progress.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

13 participants

@bnoordhuis @trevnorris @yosuke-furukawa @algesten @tellnes @chrisdickinson @Qard @xaka @charmander @mscdex @piscisaureus @ChALkeR @brendanashworth
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.