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

quadratic (?) complexity when composing fragments #686

Open
fdietze opened this issue Jul 27, 2022 · 0 comments
Open

quadratic (?) complexity when composing fragments #686

fdietze opened this issue Jul 27, 2022 · 0 comments

Comments

@fdietze
Copy link
Contributor

fdietze commented Jul 27, 2022

Concatenating 10k Fragments 10 times is much faster than concatenating 100k fragments one time. This suggests a quadratic (or nonlinear) runtime complexity.

Reproduction in ammonite (Scala 2.13.8):

import $ivy.`org.tpolecat::skunk-core:0.2.3`; import skunk._; import skunk.implicits._

def measure(code: => Any) = {val start = System.nanoTime; code; println(f"${(System.nanoTime - start)/1000000000.0}%.2fs")}

measure { for(i <- 0 until 10) Array.fill(10000)(sql"x").foldLeft(sql"")((a,b) => sql"$a$b") }
// 18s
// is much faster than
measure { Array.fill(100000)(sql"x").foldLeft(sql"")((a,b) => sql"$a$b") }
// 213s

It could be caused by repeated concatenation of a growing List.

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

No branches or pull requests

1 participant