question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to generate uuid (v4) without the hyphens in most performant way?

See original GitHub issue

I have a use-case where I need UUIDs in high volume with no hyphens in them. I understand that we can do uuid().replace(/-/g, ''). But is that performant enough? The process of replacing after generation also seems wasteful.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
broofacommented, Feb 4, 2022

@OctaneInteractive et al: uuidv4() should return a string, so the toString() is probably not necessary.

FWIW, replaceAll() is now a thing and probably slightly more performant than replace(). (Note: Requires node 15+)

> require('uuid').v4().replaceAll('-', '')
'b2d46dca936942a081c7d8b5e2e62041'
1reaction
broofacommented, Dec 7, 2020

@mateja176 Mongo DB querying? As noted above, the perf of replace() is almost certainly dwarfed by whatever Mongo is doing to process the query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

random - Efficient method to generate UUID String in Java ...
This does it: public static void main(String[] args) { final String uuid = UUID.randomUUID().toString().replace("-" ...
Read more >
You Might Not Need UUID V4 for Generating Random Identifiers
For many applications you might need to generate some kind of unique identifier to be able to get a reference to specific content....
Read more >
Java UUID - Javatpoint
The randomUUID() method randomly generate the UUID. Whenever we run the program, it generates a new UUID. The signature of the method is:...
Read more >
What is a UUID, and why should you care? - Cockroach Labs
They can be generated without the need to check against a central node, so in a distributed system, each node can generate UUIDs...
Read more >
Universally unique identifier - Wikipedia
When generated according to the standard methods, UUIDs are, for practical purposes, unique. Their uniqueness does not depend on a central registration ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found