{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/18810","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/18810/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/18810/comments","events_url":"https://api.github.com/repos/apache/spark/issues/18810/events","html_url":"https://github.com/apache/spark/pull/18810","id":247273307,"number":18810,"title":"[SPARK-21603][SQL]The wholestage codegen will be much slower then that is closed when the function is too long","user":{"login":"eatoncys","id":26834091,"avatar_url":"https://avatars3.githubusercontent.com/u/26834091?v=4","gravatar_id":"","url":"https://api.github.com/users/eatoncys","html_url":"https://github.com/eatoncys","followers_url":"https://api.github.com/users/eatoncys/followers","following_url":"https://api.github.com/users/eatoncys/following{/other_user}","gists_url":"https://api.github.com/users/eatoncys/gists{/gist_id}","starred_url":"https://api.github.com/users/eatoncys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eatoncys/subscriptions","organizations_url":"https://api.github.com/users/eatoncys/orgs","repos_url":"https://api.github.com/users/eatoncys/repos","events_url":"https://api.github.com/users/eatoncys/events{/privacy}","received_events_url":"https://api.github.com/users/eatoncys/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2017-08-02T04:56:53Z","updated_at":"2017-08-11T02:57:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/18810","html_url":"https://github.com/apache/spark/pull/18810","diff_url":"https://github.com/apache/spark/pull/18810.diff","patch_url":"https://github.com/apache/spark/pull/18810.patch"},"body":"## What changes were proposed in this pull request?\r\nClose the whole stage codegen when the function lines is longer than the maxlines which will be setted by\r\nspark.sql.codegen.MaxFunctionLength parameter, because when the function is too long , it will not get the JIT  optimizing.\r\nA benchmark test result is 10x slower when the generated function is too long :\r\n\r\nignore(\"max function length of wholestagecodegen\") {\r\n    val N = 20 << 15\r\n\r\n    val benchmark = new Benchmark(\"max function length of wholestagecodegen\", N)\r\n    def f(): Unit = sparkSession.range(N)\r\n      .selectExpr(\r\n        \"id\",\r\n        \"(id & 1023) as k1\",\r\n        \"cast(id & 1023 as double) as k2\",\r\n        \"cast(id & 1023 as int) as k3\",\r\n        \"case when id > 100 and id <= 200 then 1 else 0 end as v1\",\r\n        \"case when id > 200 and id <= 300 then 1 else 0 end as v2\",\r\n        \"case when id > 300 and id <= 400 then 1 else 0 end as v3\",\r\n        \"case when id > 400 and id <= 500 then 1 else 0 end as v4\",\r\n        \"case when id > 500 and id <= 600 then 1 else 0 end as v5\",\r\n        \"case when id > 600 and id <= 700 then 1 else 0 end as v6\",\r\n        \"case when id > 700 and id <= 800 then 1 else 0 end as v7\",\r\n        \"case when id > 800 and id <= 900 then 1 else 0 end as v8\",\r\n        \"case when id > 900 and id <= 1000 then 1 else 0 end as v9\",\r\n        \"case when id > 1000 and id <= 1100 then 1 else 0 end as v10\",\r\n        \"case when id > 1100 and id <= 1200 then 1 else 0 end as v11\",\r\n        \"case when id > 1200 and id <= 1300 then 1 else 0 end as v12\",\r\n        \"case when id > 1300 and id <= 1400 then 1 else 0 end as v13\",\r\n        \"case when id > 1400 and id <= 1500 then 1 else 0 end as v14\",\r\n        \"case when id > 1500 and id <= 1600 then 1 else 0 end as v15\",\r\n        \"case when id > 1600 and id <= 1700 then 1 else 0 end as v16\",\r\n        \"case when id > 1700 and id <= 1800 then 1 else 0 end as v17\",\r\n        \"case when id > 1800 and id <= 1900 then 1 else 0 end as v18\")\r\n      .groupBy(\"k1\", \"k2\", \"k3\")\r\n      .sum()\r\n      .collect()\r\n\r\n    benchmark.addCase(s\"codegen = F\") { iter =>\r\n      sparkSession.conf.set(\"spark.sql.codegen.wholeStage\", \"false\")\r\n      f()\r\n    }\r\n\r\n    benchmark.addCase(s\"codegen = T\") { iter =>\r\n      sparkSession.conf.set(\"spark.sql.codegen.wholeStage\", \"true\")\r\n      sparkSession.conf.set(\"spark.sql.codegen.MaxFunctionLength\", \"10000\")\r\n      f()\r\n    }\r\n\r\n    benchmark.run()\r\n\r\n    /*\r\n    Java HotSpot(TM) 64-Bit Server VM 1.8.0_111-b14 on Windows 7 6.1\r\n    Intel64 Family 6 Model 58 Stepping 9, GenuineIntel\r\n    max function length of wholestagecodegen: Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative\r\n    ------------------------------------------------------------------------------------------------\r\n    codegen = F                                    443 /  507          1.5         676.0       1.0X\r\n    codegen = T                                   3279 / 3283          0.2        5002.6       0.1X\r\n     */\r\n  }\r\n\r\n\r\n## How was this patch tested?\r\nRun the unit test\r\n"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/321722491","html_url":"https://github.com/apache/spark/pull/18810#issuecomment-321722491","issue_url":"https://api.github.com/repos/apache/spark/issues/18810","id":321722491,"user":{"login":"SparkQA","id":8108735,"avatar_url":"https://avatars1.githubusercontent.com/u/8108735?v=4","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2017-08-11T02:57:23Z","updated_at":"2017-08-11T02:57:23Z","body":"**[Test build #80518 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/80518/testReport)** for PR 18810 at commit [`6814047`](https://github.com/apache/spark/commit/6814047231044627ee85aef458c108345e129bee)."}}
{"actor":{"display_login":"SparkQA"}}