[Kmymoney-devel] [Bug 247912] New: Slow performance related to use of KHolidays in KDE 4.5

Alvaro Soliverez asoliverez at gmail.com
Sun Aug 15 03:48:38 CEST 2010


https://bugs.kde.org/show_bug.cgi?id=247912

           Summary: Slow performance related to use of KHolidays in KDE
                    4.5
           Product: kmymoney4
           Version: unspecified
          Platform: Archlinux Packages
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: NOR
         Component: general
        AssignedTo: kmymoney-devel at kde.org
        ReportedBy: asoliverez at gmail.com


Version:           unspecified (using KDE 4.5.0) 
OS:                Linux

Under KDE 4.5, KMyMoney is terribly slow when starting or using anything that
requires a call to isProcessingDay().
Going to Schedule settings and setting the region to none solves the
performance problem, but the real problem lies in the way KHoliday calculates
the holidays when isHoliday() is called.


Reproducible: Didn't try


Actual Results:  
slow performance when using schedules with holidays

Expected Results:  
it should work fast

Here is some info by John Layt on the HolidayRegion class:

isHoliday() is fairly inefficient as every time you call it with a single date,
it recalculates all the holidays in that year for every calendar system and
then checks the requested day. There is no caching or intelligence in what it
calculates. I have some optimisations planned but those will be in 4.6.
KHoliday also uses QList rather than a QHash, but that's something I can't
change.

My suggestion would be if you have a date range you need to check to instead
call this HolidayRegion method:

Holiday::List holidays( const QDate &startDate, const QDate &endDate ) const;

This will only calculate the holidays in a year once for the entire date range
and return you a list of all the holidays in the date range. You can then
iterate over the list to check your dates, or perhaps hash them, which should
be quicker. The code for isHoliday() does it like this:

bool HolidayRegion::isHoliday( const QDate &date ) const

{

Holiday::List holidayList = holidays( date );

if ( holidayList.count() > 0 ) {

foreach ( const KHolidays::Holiday &holiday, holidayList ) {

if ( holiday.dayType() == Holiday::NonWorkday ) {

return true;

}

}

}

return false;

}

As for memory usage, the HolidayRegion does cache the contents of the holiday
file in a QByteArray to save repeatedly reading the file from disk, but a
single file is only about 2k. Unfortunately it doesn't use QSharedData so
having multiple HolidayRegions around for the same country will have multiple
copies of the file.

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the KMyMoney-devel mailing list