spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maciej Bryński (JIRA) <j...@apache.org>
Subject [jira] [Commented] (SPARK-22010) Slow fromInternal conversion for TimestampType
Date Thu, 14 Sep 2017 12:01:00 GMT

    [ https://issues.apache.org/jira/browse/SPARK-22010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16166134#comment-16166134
] 

Maciej Bryński commented on SPARK-22010:
----------------------------------------

Proposition
Create constant
{code}
utc = datetime.datetime.now(tzlocal()).tzname() == 'UTC'
{code}

Then change this code to: ( https://github.com/apache/spark/blob/master/python/pyspark/sql/types.py#L196
)
{code}
y, m, d, hh, mm, ss, _, _, _ = gmtime(ts // 1000000) if utc else localtime(ts // 1000000)
datetime.datetime(y, m, d, hh, mm, ss, ts % 1000000)
{code}

This is running 30% faster if TZ != UTC and 3x faster if TZ == UTC

What do you think about such a solution ?

> Slow fromInternal conversion for TimestampType
> ----------------------------------------------
>
>                 Key: SPARK-22010
>                 URL: https://issues.apache.org/jira/browse/SPARK-22010
>             Project: Spark
>          Issue Type: Bug
>          Components: PySpark
>    Affects Versions: 2.2.0
>            Reporter: Maciej Bryński
>
> To convert timestamp type to python we are using 
> `datetime.datetime.fromtimestamp(ts // 1000000).replace(microsecond=ts % 1000000)`
> code.
> {code}
> In [34]: %%timeit
>     ...: datetime.datetime.fromtimestamp(1505383647).replace(microsecond=12344)
>     ...:
> 4.2 µs ± 558 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
> {code}
> It's slow, because:
> # we're trying to get TZ on every conversion
> # we're using replace method
> Proposed solution: custom datetime conversion and move calculation of TZ to module



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message