Repository navigation
Description
Environment
Hi, long time user. Don't think you need my system info for this one, so I'm going to skip this. I updated recently and pulled the code below from the main version of the Git Repo.
I have an issue with a calendar I've used for many years, has many events. All my other calendars work fine, all of my new calendars work fine. I run this on a raspberry pi with decent specs but also run my homebridge on it. This calendar used to be the slowest to load - one day it just stopped loading and has not loaded since.
I noticed the calendar fetcher parses the entire ical and then filters the events.
Can we fix this to make the filter happen when the calendar is loaded rather than loading the information first then filtering it?
I am fairly certain my calendar not loading is related to this. I have also seen others report calendar not loading issues, and I wonder if this is the root cause (I'm not sure what limits the size of parsed).
This is in calendarfetcher.js, see how it loads the ics and then parses after:
try {
const responseData = await response.text();
const parsed = ical.parseICS(responseData);
Log.debug(`Parsed iCal data from ${this.url} with ${Object.keys(parsed).length} entries.`);
this.events = CalendarFetcherUtils.filterEvents(parsed, {
excludedEvents: this.excludedEvents,
includePastEvents: this.includePastEvents,
maximumEntries: this.maximumEntries,
maximumNumberOfDays: this.maximumNumberOfDays
});
I feel like this is what is causing the problem.
Hopefully this is possible to do and wouldn't be problematic to implement!
Which start option are you using?
node --run server
Are you using PM2?
No
Module
None
Have you tried disabling other modules?
- Yes
- No
Have you searched if someone else has already reported the issue on the forum or in the issues?
- Yes
What did you do?
Reproduce:
Have big old calendar file; try to load; have it never load.
Have many new calendar files; no problems loading
To be fair, I haven't checked the size of the big old calendar file, but I know it has a lot of events on it...
What did you expect to happen?
I expect calendar to load.
What actually happened?
Calendar events do not load. No error.
Additional comments
Sorry I'm not doing a great job filling out the fields with all my system information for this. If this is not the reason, I'm back to the drawing board on this issue... I'm hoping that pointing out the issue in data handling I believe is causing this issue will fix the bug I'm running into.
Also thank you!! :)
Participation
- I am willing to submit a pull request for this change.
Activity
KristjanESPERANTO commentedon Apr 25, 2026
@Evarda Thank you for the report, and also for offering to open a PR. That would be welcome! 🙂
Your idea about improving handling for large ICS files makes sense. If you’d like, feel free to try an initial approach. It doesn't have to be perfect right away; the main thing is that the general approach is clear and works as a proof of concept.
sdetweil commentedon May 1, 2026
some food for thought
the blob we load is all text .
you can see it and count the events with
then you can count how many begin and end events there are
my personal calendar has 1112 events. over 13 years.
an event looks like this
to filter, we need to use the
line, in each event
a search and AI conversation produced a function like this
this will add another complete pass of the text to get all the requested events.. as the source (google, et al) does not provide a mechanism to pre-filter before download
then the ics parser will do a complete pass to turn the text into object before we can process it
this filtered my cal from 1112 events to 177
sdetweil commentedon May 4, 2026
There is a problem with this approach
If there is an event that starts outside the filter range, but has a repeating cycle that presents an event inside the calendar view range. It will be dropped from the processing list, because we are not yet processing rrule events (until after parse)
Consider your new child’s birthday, added 5 yrs ago
Anniversary, etc.
sdetweil commentedon May 4, 2026
I actually had a couple in my cal with this condition, and updated the filter (see edit above) to send all events with RRULE thru.
changed the count from 177 to 217, still a lot less than 1112
on my AMD 5950x the filter took 1243 ms
on my pi4 (running MM) it took 8624 ms
using this little script, the events were previously downloaded, so this doesn't count extract from source or transmission time
this will output the before and after filter count of events and the elapsed time to run the filter
the downloaded event list is called cal.txt
this did count the filesystem time to read the file into memory
KristjanESPERANTO commentedon May 6, 2026
@Evarda Are you working on this? 🙂
sdetweil commentedon May 6, 2026
the CPU elapsed time cost for the filter is bad.
so I thought of another approach, which doesn't cleanly work with a regex..
search for the 1st occurrence of the date, and take that match.index as the start of the events to copy.
but after looking at my ical data, the events are not in date order
perf(calendar): use async ICS parsing to avoid blocking event loop (#…
perf(calendar): pre-filter ICS text before parsing
perf(calendar): pre-filter ICS text before parsing
perf(calendar): pre-filter ICS text before parsing
perf(calendar): pre-filter ICS text before parsing
KristjanESPERANTO commentedon May 25, 2026
I was eager to work on a solution myself, and since @Evarda didn't opened a PR, I've now created one: #4168.
It's a bit complex, and I'm not sure if it's worth increasing the complexity of our codebase,
sdetweil commentedon May 25, 2026
I don’t think this is a cpu issue, I think this is a memory issue.
I’ve only seen this reported 3 times now over the years.
One solution was to build an external scraper (cron job) to fetch and filter to a file which was read by calendar. At least this removes the processing time delay out of the main path
KristjanESPERANTO commentedon May 25, 2026
An external scraper would have a real advantage for users who restart MM often - the file is already there, no download needed. But since this problem seems rare and most users don't restart frequently, the added complexity of managing a cron job outside of MagicMirror probably isn't worth it.
I think pre-filtering during the fetch cycle would solve the issue good enough - the question is only whether we use our own implementation (like PR #4168) or an external package (like
ics-filter) - both with zero additional setup for the user.sdetweil commentedon May 26, 2026
an external scraper has to download every time, as the calendar events will change..
as you said before, do we want to carry the code burden of this..
pm2 supports cron now too..
perf(calendar): pre-filter ICS text before parsing
perf(calendar): pre-filter ICS text before parsing
perf(calendar): pre-filter ICS text before parsing
perf(calendar): pre-filter ICS data before parsing (#4168)