datafaker-net / datafaker

Generating fake data for the JVM (Java, Kotlin, Groovy) has never been easier!
https://www.datafaker.net
Apache License 2.0
1.09k stars 151 forks source link

Fix memory leak #1271

Closed asolntsev closed 1 week ago

asolntsev commented 1 week ago

Probably it's easier to review this PR commit-by-commit.

This PR removes three static fields that were growing endlessly:

  1. BaseFaker.PROVIDERS_MAP
  2. BaseFaker.CLASSES
  3. FakeValuesService.REGEXP2SUPPLIER_MAP
what-the-diff[bot] commented 1 week ago

PR Summary

This Pull Request includes changes in multiple files which correspond to the optimization and improvement of our systems. Here are the crux points of this update:

These changes will ensure more transparent, efficient, and maintainable code handling, thereby providing an improved experience for our development team and more stable release for our users.

snuyanzin commented 1 week ago

Thanks for working on this

I guess we also need to run some measurement tests to see what this change brings to us I will run it today and post the result later

asolntsev commented 1 week ago

we also need to run some measurement tests

At least I run Issue1178Test, and it takes ~the same time in main branch and fix/memory-leak.

snuyanzin commented 1 week ago

there is no significant changes probably on only one improvement for DatafakerSimpleMethods.numberBetween about 10%, others are more or less same before

Benchmark                              Mode  Cnt       Score     Error   Units
DatafakerSimpleMethods.firstname      thrpt   10    9383.836 ± 110.342  ops/ms
DatafakerSimpleMethods.fullname       thrpt   10    3108.838 ±  27.933  ops/ms
DatafakerSimpleMethods.numberBetween  thrpt   10  116170.962 ± 705.899  ops/ms
DatafakerSimpleMethods.streetAddress  thrpt   10    2213.100 ±  13.656  ops/ms

Benchmark                        Mode  Cnt      Score      Error   Units
DatafakerExpressions.bothify    thrpt   10  13654.868 ±   78.549  ops/ms
DatafakerExpressions.letterify  thrpt   10  18601.883 ± 1715.311  ops/ms
DatafakerExpressions.numerify   thrpt   10  16980.816 ±  972.231  ops/ms
DatafakerExpressions.regexify   thrpt   10  19546.992 ± 2126.820  ops/ms

Benchmark                  Mode  Cnt    Score    Error   Units
DatafakerCsvjson.csvJson  thrpt   10  460.369 ± 44.570  ops/ms

after

===============================================================
Benchmark                              Mode  Cnt       Score     Error   Units
DatafakerSimpleMethods.firstname      thrpt   10    9612.673 ± 171.756  ops/ms
DatafakerSimpleMethods.fullname       thrpt   10    3137.267 ±  69.310  ops/ms
DatafakerSimpleMethods.numberBetween  thrpt   10  132792.389 ± 277.564  ops/ms
DatafakerSimpleMethods.streetAddress  thrpt   10    2258.682 ±  31.129  ops/ms

Benchmark                        Mode  Cnt      Score      Error   Units
DatafakerExpressions.bothify    thrpt   10  13748.220 ± 1365.136  ops/ms
DatafakerExpressions.letterify  thrpt   10  20836.751 ±  490.235  ops/ms
DatafakerExpressions.numerify   thrpt   10  19378.905 ± 2497.980  ops/ms
DatafakerExpressions.regexify   thrpt   10  21656.561 ±  271.221  ops/ms

Benchmark                  Mode  Cnt    Score    Error   Units
DatafakerCsvjson.csvJson  thrpt   10  479.511 ± 12.053  ops/ms
kingthorin commented 1 week ago

Thank you!