[ 
https://issues.apache.org/jira/browse/SPARK-58027?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated SPARK-58027:
-----------------------------------
    Labels: pull-request-available  (was: )

> Avoid unnecessary Matcher allocation in SparkDateTimeUtils.getZoneId for 
> region-based zone IDs
> ----------------------------------------------------------------------------------------------
>
>                 Key: SPARK-58027
>                 URL: https://issues.apache.org/jira/browse/SPARK-58027
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 5.0.0
>            Reporter: Yang Jie
>            Priority: Major
>              Labels: pull-request-available
>
> `SparkDateTimeUtils.getZoneId` runs two regex `replaceFirst` calls on every 
> invocation to normalize the legacy `(+|-)h:mm` and `(+|-)hh:m` zone-offset 
> formats (supported before Spark 3.0):
> {code:scala}
> var formattedZoneId = singleHourTz.matcher(timeZoneId).replaceFirst("$10$2:")
> formattedZoneId = 
> singleMinuteTz.matcher(formattedZoneId).replaceFirst("$1$2:0$3")
> ZoneId.of(formattedZoneId, ZoneId.SHORT_IDS)
> {code}
> Both patterns are anchored on a leading sign character `(+|-)`. Region-based 
> IDs such as `UTC`, `America/New_York`, or `GMT+8` -- the overwhelming 
> majority of inputs -- can never match, yet each call still allocates two 
> `Matcher` instances and scans the string twice before `ZoneId.of` does the 
> real work.
> This guards the normalization so the two regexes only run when the input 
> starts with a sign character, skipping the `Matcher` allocations for the 
> common region-id case. The change is behavior-preserving: since both patterns 
> are anchored on the leading sign, an input that does not start with `+`/`-` 
> is returned unchanged by `replaceFirst` today, which is exactly what the 
> guarded `else` branch returns.
> This is a small clarity and allocation cleanup on the shared `getZoneId` 
> helper, not a headline performance change.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to