Skip to content

perf: skip redundant mappertag rebuild - #98

Merged
bxcodec merged 3 commits into
go-faker:mainfrom
catdevman:perf-skip-redundant-mappertag-rebuild
Jul 25, 2026
Merged

bxcodec merged 3 commits into
go-faker:mainfrom
catdevman:perf-skip-redundant-mappertag-rebuild

Conversation

@catdevman

Copy link
Copy Markdown
Contributor

The will close #97

…ebuild

Rename: this fork needs its own import path so a downstream module (mockagen)
can require it directly instead of via a bare local replace against the
upstream module path.

Perf fix: FakeData() called initOption() -> initMapperTagWithOption() on
every single invocation, unconditionally re-storing ~9 Internet/Networker
generator functions into the global mapperTag map regardless of whether any
per-call options were actually passed. Profiling a high-volume concurrent
caller (github.com/catdevman/mockagen, ~1M+ FakeData calls across many
goroutines) showed this was a significant share of total CPU time, plus lock
contention on mapperTag from doing it concurrently on every call.

Guard the common case (no per-call options, i.e. plain faker.FakeData(&v))
behind a sync.Once so the map is only populated once instead of on every
call. Calls that do pass options still re-run every time, so existing
per-call customization (e.g. a custom email domain option) is unaffected.
Guard the no-options case behind sync.Once to avoid re-populating the global
mapperTag map on every call, cutting repeated work and lock contention.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.31%. Comparing base (9f848d5) to head (b734204).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
+ Coverage   81.09%   81.31%   +0.22%     
==========================================
  Files          16       16              
  Lines        2174     2184      +10     
==========================================
+ Hits         1763     1776      +13     
+ Misses        352      350       -2     
+ Partials       59       58       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bxcodec bxcodec changed the title Perf skip redundant mappertag rebuild perf: skip redundant mappertag rebuild Jul 25, 2026

@bxcodec bxcodec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!
LGTM

Thanks for the PR @catdevman

@bxcodec
bxcodec merged commit 7ad1238 into go-faker:main Jul 25, 2026
2 checks passed
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.

FakeData() rebuilds the entire Internet/Networker tag registry on every call, even with no per-call options

3 participants