Skip to content

fix cubic time of _make_unique_tzname in get_transitions - #2152

Open
shamsManna wants to merge 1 commit into
PyCalendar:mainfrom
shamsManna:vtimezone-unique-tzname
Open

shamsManna wants to merge 1 commit into
PyCalendar:mainfrom
shamsManna:vtimezone-unique-tzname

Conversation

@shamsManna

Copy link
Copy Markdown
Contributor

Linked issue

Description

Timezone.get_transitions names a STANDARD or DAYLIGHT subcomponent without TZNAME after its TZID, DTSTART and offsets, and _make_unique_tzname kept appending _1 until the name was free, so n equal subcomponents build names of length 2n in cubic time. With the pytz provider this runs during Calendar.from_ical for any VTIMEZONE with an unknown TZID: 4000 such subcomponents (363 KiB) take 22 s to parse, 0.37 s with the fix, which remembers the next numeric suffix per name (EST_1, EST_2, ...) and resolves the TODO there. Different input from #2047, which only limits RRULE frequency.

Checklist

  • I added a change log entry, following the instructions in all subsections under Change log requirements.
  • I followed icalendar's Artificial intelligence policy and disclosed my Responsible AI use in my commit messages, if applicable.
  • I added or updated tests, if applicable.
  • I ran and ensured all tests pass locally by following Run tests.
  • I added or edited documentation as necessary, both as docstrings to be rendered in the API documentation and narrative documentation, following the Style guide.

Additional information

Timings for Calendar.from_ical with use_pytz() and n equal subcomponents without TZNAME: 1000: 0.34 s -> 0.12 s, 2000: 1.7 s -> 0.20 s, 4000: 22 s -> 0.37 s, 8000: -> 0.73 s. Locally, test_issue_1445.py and test_rfc_6868.py (9 tests) fail on main as well; everything else passes.

Timezone.get_transitions names a STANDARD or DAYLIGHT subcomponent
without TZNAME after its TZID, DTSTART and offsets, and
_make_unique_tzname appended "_1" until the name was unused. n equal
subcomponents therefore built names of length 2n and took cubic time:
with the pytz provider, Calendar.from_ical of a 363 KiB VTIMEZONE with
4000 such subcomponents took 22 s. Remember the next numeric suffix per
name, so a repeated name gets _1, _2, ... in linear time (0.37 s).

AI: Claude Opus 5.5 (claude-opus-5-5) via Claude Code.
Prompt: find a security bug in icalendar, reproduce it, and write a
minimal fix with a regression test and change log entry.
Output: (this commit), reviewed by the author.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @shamsManna! A maintainer will review it shortly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant