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: remove regexp-clone #11327

Merged
merged 5 commits into from
Feb 7, 2022
Merged

perf: remove regexp-clone #11327

merged 5 commits into from
Feb 7, 2022

Conversation

Uzlopak
Copy link
Collaborator

@Uzlopak Uzlopak commented Feb 4, 2022

Cloning an regexp does not need an external library.

@Uzlopak Uzlopak changed the title remove regexp-clone impr: remove regexp-clone Feb 4, 2022
Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

Glad that we're getting rid of more and more dependencies.
Have a couple of questions and suggestions regarding the introduced changes, but I'm happy with that change.

@Uzlopak
Copy link
Collaborator Author

Uzlopak commented Feb 5, 2022

@AbdelrahmanHafez
Fixed the comments.

@Uzlopak
Copy link
Collaborator Author

Uzlopak commented Feb 6, 2022

@AbdelrahmanHafez
@vkarpov15
Also here some benchmarks:

regexp-clone x 2,177,401 ops/sec ±1.10% (87 runs sampled)
new RegExp(regex) x 4,872,620 ops/sec ±0.74% (91 runs sampled)
new RegExp(regex.source, regex.flags) x 5,274,696 ops/sec ±0.73% (89 runs sampled)

So intuitivly, we have implemented the fastest cloning

const Benchmark = require('benchmark');
const cloneRegExp = require('regexp-clone');

const regex = /^a$/g;

new Benchmark.Suite()
  .add('regexp-clone', function () {
    const newRegex = cloneRegExp(regex)
  })
  .add('new RegExp(regex)', function () {
    const newRegex = new RegExp(regex);
    if (typeof regex.lastIndex === "number") {
        newRegex.lastIndex = regex.lastIndex;
    }
  })
  .add('new RegExp(regex.source, regex.flags)', function () {
    const newRegex = new RegExp(regex.source, regex.flags);
    if (typeof regex.lastIndex === "number") {
        newRegex.lastIndex = regex.lastIndex;
    }
  })
  .on('cycle', function (evt) {
    console.log(String(evt.target));
  })
  .run();

@Uzlopak Uzlopak changed the title impr: remove regexp-clone perf: remove regexp-clone Feb 6, 2022
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Nice, thanks 👍 I also agree about removing deps.

@vkarpov15 vkarpov15 added this to the 6.2.1 milestone Feb 7, 2022
@vkarpov15 vkarpov15 merged commit 1d94158 into Automattic:master Feb 7, 2022
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

3 participants