Skip to content

Excessive metadata instantiation for PhoneNumber.parse().isValid(), 245+ object instances created unnecessarily #101

@YazanFarrah

Description

@YazanFarrah

When calling PhoneNumber.parse('+$phoneNumber').isValid(), the package initializes hundreds of PhoneMetadata-related objects in memory on each import, regardless of the country used.

After profiling, these are the counts observed:

PhoneMetadata → 245 instances

PhoneMetadataPatterns → 245 instances

IsoCode → 245 instances

PhoneMetadataLengths → 178 instances

This initialization occurs even when validating a single phone number, resulting in unnecessary memory usage and slower startup.

Expected Behavior:

The library should lazily load or cache only the metadata required for:

The detected country code, or

The specific ISO region used during parsing.

This would reduce startup overhead dramatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions