-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
Speed up uuid.UUID string parsing #150226
Copy link
Copy link
Closed as not planned
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Fields
Give feedbackNo fields configured for issues without a type.
uuid.UUID.__init__()normalizes every string input by removingurn:,uuid:, braces, and hyphens, even for documented inputs where only one of those operations is needed.The common documented forms are:
1234567812345678123456781234567812345678-1234-5678-1234-567812345678{12345678-1234-5678-1234-567812345678}urn:uuid:12345678-1234-5678-1234-567812345678A small refactor can handle the documented
urn:uuid:prefix directly withstr.removeprefix()and keep the existing broader normalization as a fallback for legacy accepted inputs.On a local Windows debug build, a same-process benchmark comparing
origin/mainwith the patchedLib/uuid.pyshowed improvements for the documented forms:I also verified
test_uuidpasses on the same debug build.Linked PRs