Skip to content

Perf: remove Regex in zip entry lookup and move I/O outside lock in geocoder#314

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/identify-slow-code-improvements
Draft

Perf: remove Regex in zip entry lookup and move I/O outside lock in geocoder#314
Copilot wants to merge 2 commits intomainfrom
copilot/identify-slow-code-improvements

Conversation

Copy link

Copilot AI commented Feb 28, 2026

Two inefficiencies in PhoneNumberOfflineGeocoder — one creating unnecessary Regex objects per zip entry comparison, another holding a lock across slow file I/O.

Changes

  • Replace Regex.Replace with string ops in GetManifestZipFileStream: the static Regex.Replace call internally constructs a Regex object on every zip entry during each geocoding lookup. Replaced with string.Replace(char, char) — no allocation, no compilation overhead.

    // Before
    archive.Entries.First(p => Regex.Replace(p.FullName, "[\\\\/]", ".") == fileName);
    
    // After
    archive.Entries.First(p => p.FullName.Replace('\\', '.').Replace('/', '.') == fileName);
  • Move file I/O outside the lock in GetPhonePrefixDescriptions: previously the availablePhonePrefixMaps lock was held for the full duration of zip decompression + parsing, serializing all threads behind a single load. Changed to double-check locking: cache lookup under lock → load without lock → store under lock. Concurrent requests for different locales no longer block each other.

  • Removed unused using System.Text.RegularExpressions following the Regex removal.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…eocoder

Co-authored-by: wmundev <30316250+wmundev@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements for inefficient code Perf: remove Regex in zip entry lookup and move I/O outside lock in geocoder Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants