Skip to content

Commit

Permalink
feat: Only initialize BusinessCalendar caches when data is accessed a…
Browse files Browse the repository at this point in the history
…nd improve caching performance (#5378)

Makes BusinessCalendar caches populate only when accessed to avoid slow
worker initialization. Additionally, caching in various operations has
been improved to yield better performance.

Resolves #5377

Benchmark:
```groovy
n = 1_000_000
npart = 10
t = emptyTable(n)
        .updateView("Part = ii%npart", "Today = todayLocalDate()")

tp = t.partitionBy("Part").proxy()

c = calendar()

timeit = { name, table, query ->
    c.clearCache()
    start = System.currentTimeMillis()
    rst = table.update(query)
    end = System.currentTimeMillis()
    println("TIME: ${name}: ${end-start} ms")
}

istart = parseInstant("2022-01-01T01:01:01 ET")
iend = parseInstant("2024-06-01T01:01:01 ET")

timeit("calendarDayOld-NORMAL", t, "CD = c.calendarDay(Today)")
timeit("calendarDayOld-PART", tp, "CD = c.calendarDay(Today)")

timeit("diffBusinessYearsOld-NORMAL", t, "CD = c.diffBusinessYears(istart, iend)")
timeit("diffBusinessYearsOld-PART", tp, "CD = c.diffBusinessYears(istart, iend)")

println("DONE")
```

Performance:
```
// 1M - NEW
//TIME: calendarDayOld-NORMAL: 266 ms
//TIME: calendarDayOld-PART: 299 ms
//TIME: diffBusinessYearsOld-NORMAL: 5937 ms
//TIME: diffBusinessYearsOld-PART: 6664 ms <<<<

// 1M - v0.33.3
//TIME: calendarDayOld-NORMAL: 366 ms
//TIME: calendarDayOld-PART: 327 ms
//TIME: diffBusinessYearsOld-NORMAL: 20384 ms
//TIME: diffBusinessYearsOld-PART: 5549 ms <<<<

// 10M - NEW
//TIME: calendarDayOld-NORMAL: 449 ms
//TIME: calendarDayOld-PART: 548 ms
//TIME: diffBusinessYearsOld-NORMAL: 58883 ms
//TIME: diffBusinessYearsOld-PART: 67362 ms <<<<

// 10M - v0.33.3
//TIME: calendarDayOld-NORMAL: 522 ms
//TIME: calendarDayOld-PART: 704 ms
//TIME: diffBusinessYearsOld-NORMAL: 195916 ms
//TIME: diffBusinessYearsOld-PART: 49411 ms <<<<
```
Note1: `v0.33.0` times do not include initialization times, but the new
values do.
Note2: There appears to be contention or initialization overhead in the
partitioned table case yielding slightly worse performance.
  • Loading branch information
chipkent authored Oct 23, 2024
1 parent 0b7726a commit 1635218
Show file tree
Hide file tree
Showing 12 changed files with 1,445 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static void main(String[] args) throws ClassNotFoundException, IOExceptio
excludes.add("description");
excludes.add("firstValidDate");
excludes.add("lastValidDate");
excludes.add("clearCache");

StaticCalendarMethodsGenerator gen =
new StaticCalendarMethodsGenerator(gradleTask, packageName, className, imports,
Expand Down
Loading

0 comments on commit 1635218

Please sign in to comment.