[jira] [Updated] (SPARK-26205) Optimize InSet expression for bytes, shorts, ints, dates

2019-02-28 Thread Anton Okolnychyi (JIRA)


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

Anton Okolnychyi updated SPARK-26205:
-
Description: 
{{In}} expressions are compiled into a sequence of if-else statements, which 
results in O\(n\) time complexity. {{InSet}} is an optimized version of {{In}}, 
which is supposed to improve the performance if the number of elements is big 
enough. However, {{InSet}} actually degrades the performance in many cases due 
to various reasons (benchmarks were created in SPARK-26203 and solutions to the 
boxing problem are discussed in SPARK-26204).

The main idea of this JIRA is to use Java {{switch}} statements to 
significantly improve the performance of {{InSet}} expressions for bytes, 
shorts, ints, dates. All {{switch}} statements are compiled into 
{{tableswitch}} and {{lookupswitch}} bytecode instructions. We will have O\(1\) 
time complexity if our case values are compact and {{tableswitch}} can be used. 
Otherwise, {{lookupswitch}} will give us O\(log n\). Our local benchmarks show 
that this logic is more than two times faster even on 500+ elements than using 
primitive collections in {{InSet}} expressions. As Spark is using Scala 
{{HashSet}} right now, the performance gain will be is even bigger.

See 
[here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10] 
and 
[here|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
 for more information.

  was:
Currently, {{In}} expressions are compiled into a sequence of if-else 
statements, which results in O\(n\) time complexity. {{InSet}} is an optimized 
version of {{In}}, which is supposed to improve the performance if the number 
of elements is big enough. However, {{InSet}} actually degrades the performance 
in many cases due to various reasons (benchmarks will be available in 
SPARK-26203 and solutions are discussed in SPARK-26204).

The main idea of this JIRA is to make use of {{tableswitch}} and 
{{lookupswitch}} bytecode instructions. In short, we can improve our time 
complexity from O\(n\) to O\(1\) or at least O\(log n\) by using Java 
{{switch}} statements. We will have O\(1\) time complexity if our case values 
are compact and {{tableswitch}} can be used. Otherwise, {{lookupswitch}} will 
give us O\(log n\). 

An important benefit of the proposed approach is that we do not have to pay an 
extra cost for autoboxing as in case of {{InSet}}. As a consequence, we can 
substantially outperform {{InSet}} even on 250+ elements.

See 
[here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10] 
and 
[here|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
 for more information.


> Optimize InSet expression for bytes, shorts, ints, dates
> 
>
> Key: SPARK-26205
> URL: https://issues.apache.org/jira/browse/SPARK-26205
> Project: Spark
>  Issue Type: Improvement
>  Components: SQL
>Affects Versions: 3.0.0
>Reporter: Anton Okolnychyi
>Priority: Major
>
> {{In}} expressions are compiled into a sequence of if-else statements, which 
> results in O\(n\) time complexity. {{InSet}} is an optimized version of 
> {{In}}, which is supposed to improve the performance if the number of 
> elements is big enough. However, {{InSet}} actually degrades the performance 
> in many cases due to various reasons (benchmarks were created in SPARK-26203 
> and solutions to the boxing problem are discussed in SPARK-26204).
> The main idea of this JIRA is to use Java {{switch}} statements to 
> significantly improve the performance of {{InSet}} expressions for bytes, 
> shorts, ints, dates. All {{switch}} statements are compiled into 
> {{tableswitch}} and {{lookupswitch}} bytecode instructions. We will have 
> O\(1\) time complexity if our case values are compact and {{tableswitch}} can 
> be used. Otherwise, {{lookupswitch}} will give us O\(log n\). Our local 
> benchmarks show that this logic is more than two times faster even on 500+ 
> elements than using primitive collections in {{InSet}} expressions. As Spark 
> is using Scala {{HashSet}} right now, the performance gain will be is even 
> bigger.
> See 
> [here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10]
>  and 
> [here|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
>  for more information.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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



[jira] [Updated] (SPARK-26205) Optimize InSet expression for bytes, shorts, ints, dates

2019-02-28 Thread Anton Okolnychyi (JIRA)


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

Anton Okolnychyi updated SPARK-26205:
-
Summary: Optimize InSet expression for bytes, shorts, ints, dates  (was: 
Optimize In expression for bytes, shorts, ints)

> Optimize InSet expression for bytes, shorts, ints, dates
> 
>
> Key: SPARK-26205
> URL: https://issues.apache.org/jira/browse/SPARK-26205
> Project: Spark
>  Issue Type: Improvement
>  Components: SQL
>Affects Versions: 3.0.0
>Reporter: Anton Okolnychyi
>Priority: Major
>
> Currently, {{In}} expressions are compiled into a sequence of if-else 
> statements, which results in O\(n\) time complexity. {{InSet}} is an 
> optimized version of {{In}}, which is supposed to improve the performance if 
> the number of elements is big enough. However, {{InSet}} actually degrades 
> the performance in many cases due to various reasons (benchmarks will be 
> available in SPARK-26203 and solutions are discussed in SPARK-26204).
> The main idea of this JIRA is to make use of {{tableswitch}} and 
> {{lookupswitch}} bytecode instructions. In short, we can improve our time 
> complexity from O\(n\) to O\(1\) or at least O\(log n\) by using Java 
> {{switch}} statements. We will have O\(1\) time complexity if our case values 
> are compact and {{tableswitch}} can be used. Otherwise, {{lookupswitch}} will 
> give us O\(log n\). 
> An important benefit of the proposed approach is that we do not have to pay 
> an extra cost for autoboxing as in case of {{InSet}}. As a consequence, we 
> can substantially outperform {{InSet}} even on 250+ elements.
> See 
> [here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10]
>  and 
> [here|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
>  for more information.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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



[jira] [Updated] (SPARK-26205) Optimize In expression for bytes, shorts, ints

2018-11-28 Thread Anton Okolnychyi (JIRA)


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

Anton Okolnychyi updated SPARK-26205:
-
Description: 
Currently, {{In}} expressions are compiled into a sequence of if-else 
statements, which results in O\(n\) time complexity. {{InSet}} is an optimized 
version of {{In}}, which is supposed to improve the performance if the number 
of elements is big enough. However, {{InSet}} actually degrades the performance 
in many cases due to various reasons (benchmarks will be available in 
SPARK-26203 and solutions are discussed in SPARK-26204).

The main idea of this JIRA is to make use of {{tableswitch}} and 
{{lookupswitch}} bytecode instructions. In short, we can improve our time 
complexity from O\(n\) to O\(1\) or at least O\(log n\) by using Java 
{{switch}} statements. We will have O\(1\) time complexity if our case values 
are compact and {{tableswitch}} can be used. Otherwise, {{lookupswitch}} will 
give us O\(log n\). 

An important benefit of the proposed approach is that we do not have to pay an 
extra cost for autoboxing as in case of {{InSet}}. As a consequence, we can 
substantially outperform {{InSet}} even on 250+ elements.

See 
[here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10] 
and 
[here|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
 for more information.

  was:
Currently, {{In}} expressions are compiled into a sequence of if-else 
statements, which results in O\(n\) time complexity. {{InSet}} is an optimized 
version of {{In}}, which is supposed to improve the performance if the number 
of elements is big enough. However, {{InSet}} actually degrades the performance 
in many cases due to various reasons (benchmarks will be available in 
SPARK-26203 and solutions are discussed in SPARK-26204).

The main idea of this JIRA is to make use of {{tableswitch}} and 
{{lookupswitch}} bytecode instructions. In short, we can improve our time 
complexity from O\(n\) to O\(1\) or at least O\(log n\) by using Java 
{{switch}} statements. We will have O\(1\) time complexity if our case values 
are compact and {{tableswitch}} can be used. Otherwise, {{lookupswitch}} will 
give us O\(log n\). 

An important benefit of the proposed approach is that we do not have to pay an 
extra cost for autoboxing as in case of {{InSet}}. As a consequence, we can 
substantially outperform {{InSet}} even on 250+ elements.

See 
[here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10] 
and here for 
[more|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
 information.


> Optimize In expression for bytes, shorts, ints
> --
>
> Key: SPARK-26205
> URL: https://issues.apache.org/jira/browse/SPARK-26205
> Project: Spark
>  Issue Type: Improvement
>  Components: SQL
>Affects Versions: 3.0.0
>Reporter: Anton Okolnychyi
>Priority: Major
>
> Currently, {{In}} expressions are compiled into a sequence of if-else 
> statements, which results in O\(n\) time complexity. {{InSet}} is an 
> optimized version of {{In}}, which is supposed to improve the performance if 
> the number of elements is big enough. However, {{InSet}} actually degrades 
> the performance in many cases due to various reasons (benchmarks will be 
> available in SPARK-26203 and solutions are discussed in SPARK-26204).
> The main idea of this JIRA is to make use of {{tableswitch}} and 
> {{lookupswitch}} bytecode instructions. In short, we can improve our time 
> complexity from O\(n\) to O\(1\) or at least O\(log n\) by using Java 
> {{switch}} statements. We will have O\(1\) time complexity if our case values 
> are compact and {{tableswitch}} can be used. Otherwise, {{lookupswitch}} will 
> give us O\(log n\). 
> An important benefit of the proposed approach is that we do not have to pay 
> an extra cost for autoboxing as in case of {{InSet}}. As a consequence, we 
> can substantially outperform {{InSet}} even on 250+ elements.
> See 
> [here|https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.10]
>  and 
> [here|https://stackoverflow.com/questions/10287700/difference-between-jvms-lookupswitch-and-tableswitch]
>  for more information.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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