Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance optimization by ReifyStatement #823

Merged
merged 2 commits into from
Jul 7, 2017
Merged

performance optimization by ReifyStatement #823

merged 2 commits into from
Jul 7, 2017

Conversation

1178615156
Copy link

@1178615156 1178615156 commented Jul 6, 2017

Problem

case class TestTable(id: Long , name: String)
val testTable = quote(query[TestTable])
val K = 1000
val ids = 1L to (100L * K)
val query = ctx.run(testTable .filter(e => liftQuery(ids).contains(e.id)))

the query will take long long time when ids size is big (E.g 100000)
😭 #811 is not solve it completely

Solution

use the O(n) algorithm to replace the old O(n*2) algorithm

Result

test code

val time = org.scalameter.config().withWarmer(Warmer.Zero).measure(
  query 
)
println(time)

database is empty
before : 71145.496378 ms
after : 776.846794 ms
😄

Checklist

  • Unit test all changes
  • Update README.md if applicable
  • Add [WIP] to the pull request title if it's work in progress
  • Squash commits that aren't meaningful changes
  • Run sbt scalariformFormat test:scalariformFormat to make sure that the source files are formatted

@getquill/maintainers

@1178615156 1178615156 changed the title performance optimization by ReifyStatement [WIP]performance optimization by ReifyStatement Jul 6, 2017
Copy link
Collaborator

@mosyp mosyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome!
Is it finished? If yes then please rebase changes into single commit

token2sql(expanded, liftingPlaceholder)
}

private def token2sql(token: Token, liftingPlaceholder: Int => String): (String, List[ScalarLift]) = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please rename it, quill-core is not bound to sql, cql etc.

}

private def token2sql(token: Token, liftingPlaceholder: Int => String): (String, List[ScalarLift]) = {
@tailrec
Copy link
Collaborator

@jilen jilen Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could simply convert the List to Vector to solve append performance

@1178615156
Copy link
Author

@jilen the string + string it is O(n); so just replace List[ScalarLift] to Vector[ScalarLift] that is not enough

@1178615156 1178615156 changed the title [WIP]performance optimization by ReifyStatement performance optimization by ReifyStatement Jul 7, 2017
@mosyp
Copy link
Collaborator

mosyp commented Jul 7, 2017

Thank you!

@mosyp mosyp merged commit cda1c3f into zio:master Jul 7, 2017
@1178615156 1178615156 deleted the performance-optimization branch July 8, 2017 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants