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

Consider replacing the dependency on hyperid with native crypto module #442

Closed
mdstaff opened this issue Dec 20, 2022 · 2 comments
Closed

Comments

@mdstaff
Copy link

mdstaff commented Dec 20, 2022

Feature Request

A single module hyperid imports the base library uuid for generating Ids. This is now supported by default since nodejs 14.17 using the "crypto" module and the "randomUUID" method.

NodeJS 14.X docs about randomUUID: https://nodejs.org/docs/latest-v14.x/api/crypto.html#crypto_crypto_randomuuid_options

Desired Behavior

Remove external dependencies in favor of native nodejs uuid generation

Motivation

Simplicity and reduced asset sizes

Implementation

Replace body of /src/uitilities/createUid.ts with the following:

import { randomUUID } from 'crypto';

export const createUid = (): string => {
  return randomUUID();
};

I can open a PR if that would be helpful.

@gajus
Copy link
Owner

gajus commented Jan 31, 2023

I think the historical reason for not using crypto was performance.

crypto.randomUUID x 17,421,022 ops/sec ±1.05% (92 runs sampled)
crypto.random x 313,547 ops/sec ±2.88% (82 runs sampled)
hyperid - fixed length, url safe x 20,158,778 ops/sec ±0.54% (94 runs sampled)

However, it looks like randomUUID is comparable in terms of performance.

I cannot think of any reason not to add this change.

@gajus gajus closed this as completed in 577d7cc Feb 23, 2023
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 33.0.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants