Relatively high memory footprint of Jollyday #412
-
Hi, As we had some memory issues, we were wondering whether we are properly reusing the Below is our code using Jollyday: Set<String> supportedSet = HolidayManager.getSupportedCalendarCodes();
for (String code : supportedSet) {
CalendarHierarchy hierarchy = HolidayManager.getInstance(ManagerParameters.create(code))
.getCalendarHierarchy();
recursiveHolidays(hierarchy, null, null);
} It also defines two additional methods, that use it, of which only one uses private static boolean testHolidays(String[] countries, LocalDate date) {
for (String holidayCode : countries) {
String[] args = holidayCode.split("_");
String[] adjArgs = Arrays.copyOfRange(args, 1, args.length);
HolidayManager manager = HolidayManager.getInstance(ManagerParameters.create(args[0]));
if (manager.isHoliday(date, adjArgs)) {
return true;
}
}
return false;
} So in total it uses the classes The DTO class defines the following method using Jollyday: public CalendarView view(boolean termsOnly) {
[...]
for (String holidayCode : holidaySet) {
String[] args = holidayCode.split("_");
String[] adjArgs = Arrays.copyOfRange(args, 1, args.length);
HolidayManager manager = HolidayManager.getInstance(ManagerParameters.create(args[0]));
Set<Holiday> holidaySet = manager.getHolidays(startDate, endDate, adjArgs);
holidaySet.forEach(holiday -> {
List<CalendarItem> existingList = calendar.getOrDefault(holiday.getDate(), new LinkedList<>());
existingList.add(new CalendarItem(holiday.getDescription(), holidayCode));
calendar.put(holiday.getDate(), existingList);
});
}
return new CalendarView(calendar, this.holidaySet);
} So in total it uses the classes Is this the intended way to achieve this or should this be done differently to save memory resources? Are there memory improvements to be made upstream in Jollyday? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
@XSpielinbox thanks for your reply. We need to look into that and add some tests. What you can do to reduce the memory is to only create a HolidayManager for each country once and hold it in memory. This is how we do it in the Zeiterfassung https://github.com/urlaubsverwaltung/zeiterfassung/blob/main/src/main/java/de/focusshift/zeiterfassung/publicholiday/PublicHolidayConfiguration.java |
Beta Was this translation helpful? Give feedback.
I digged into the code in the last couple of weeks and added tests and looked after memory leaks, but at the moment I did not find any. Could you maybe provide a heapdump or a Statistik of the number of classes that were created?