Do not create RegExpContext each time#1849
Conversation
PR Summary
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1849 +/- ##
============================================
- Coverage 92.42% 92.39% -0.03%
+ Complexity 3519 3516 -3
============================================
Files 344 344
Lines 6969 6968 -1
Branches 684 684
============================================
- Hits 6441 6438 -3
- Misses 362 366 +4
+ Partials 166 164 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I don't understand how a simple record Also, is the new code effectively the same?
|
|
Seems like these benchmarks could be added to our test suite and that they should be expanded for multi-locale scenarios. |
there is at least one missing piece here Now it is non static. It means for every instance of Also there is Another test System.out.println(faker.expression("#{Name.name}#{Name.name}"));
System.out.println(faker.expression("#{Name.name}"));
System.out.println(faker.doWith(() -> faker.expression("#{Name.name}"), Locale.JAPANESE));
System.out.println(faker.expression("#{Name.name}#{Name.name}"));
Faker faker2 = new Faker();
System.out.println(faker2.expression("#{Name.name}#{Name.name}"));
System.out.println(faker2.expression("#{Name.name}"));
System.out.println(faker2.doWith(() -> faker2.expression("#{Name.name}"), Locale.JAPANESE));
System.out.println(faker2.expression("#{Name.name}#{Name.name}"));shows |
even if it is fast it doesn't mean it is free @Benchmark
@BenchmarkMode(Mode.Throughput)
public void one(Blackhole blackhole) {
blackhole.consume(0);
}vs @Benchmark
@BenchmarkMode(Mode.Throughput)
public void one(Blackhole blackhole) {
blackhole.consume(new myRecord(reg, context, resolver)); // all arg are consts here
}shows vs |
IIRC the license might be an issue since there is another license for jmh that's why we have a separate project https://github.com/datafaker-net/datafaker-benchmark |
RegExpContextis created each time making allocation.This could be avoided.
Even more small benchmark with methods with expressions
shows that it can improve throughput about 10%
like
before
after