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

memoize various read-only arrays #139

Merged
merged 12 commits into from
Jun 1, 2023
Merged

memoize various read-only arrays #139

merged 12 commits into from
Jun 1, 2023

Conversation

sean-
Copy link
Contributor

@sean- sean- commented May 31, 2023

Description

Cache array operations to reduce memory utilization and CPU time associated with heap management. faker is now no longer in the hot path when generating random data.

@sean- sean- changed the title person: cache firstnames and name formats memoize various read-only arrays May 31, 2023
@sean- sean- marked this pull request as ready for review May 31, 2023 18:53
@jaswdr
Copy link
Owner

jaswdr commented Jun 1, 2023

LGTM, this is an excellent catch and improvement.

@jaswdr jaswdr merged commit 190b989 into jaswdr:master Jun 1, 2023
@jaswdr
Copy link
Owner

jaswdr commented Jun 1, 2023

Congratulations for your first contribution 🎉 I'll follow up on this topic and start to check benchmarks on generators performance.

@jaswdr
Copy link
Owner

jaswdr commented Jun 1, 2023

Changes released in v1.18.0

@sean- sean- deleted the cache-ops branch June 1, 2023 17:07
@sean-
Copy link
Contributor Author

sean- commented Jun 1, 2023

There's some other low-hanging fruit in the following two that I expect to take a pass at, too, if they end up being critical (vs just inefficient):

  • faker/internet.go

    Lines 49 to 50 in 614e97a

    name = strings.ToLower(name)
    name = validEmailOnlyValidCharacters.ReplaceAllString(name, "_")
  • faker/internet.go

    Lines 61 to 64 in 614e97a

    user = strings.Replace(user, "{{firstName}}", i.transformIntoValidEmailName(p.FirstName()), 1)
    // {{lastName}}
    user = strings.Replace(user, "{{lastName}}", i.transformIntoValidEmailName(p.LastName()), 1)

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.

2 participants