Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 5e035a1

Browse files
committed
Better skip algo; Better attr/stype comparison; GC-friendly ChangesPerformer
1 parent 72a3ba9 commit 5e035a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1196
-756
lines changed

bench/src/main/scala/levsha/benchmark/DiffRenderContextBenchmark.scala

Lines changed: 334 additions & 311 deletions
Large diffs are not rendered by default.
Lines changed: 151 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,151 @@
1-
package levsha.benchmark
2-
3-
import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, State}
4-
import levsha.dsl.SymbolDsl
5-
6-
@State(Scope.Benchmark)
7-
class StaticRenderingComparision {
8-
9-
import StaticRenderingComparision.engines
10-
11-
// TODO "beard"
12-
@Param(Array("levsha", "scalatags", "twirl"))
13-
var engineName: String = _
14-
15-
@Benchmark def simpleHtml(): Unit = engines(engineName).simpleHtml()
16-
@Benchmark def withVariables(): Unit = engines(engineName).withVariables()
17-
@Benchmark def withConditionAndLoop(): Unit = engines(engineName).withConditionAndLoop()
18-
}
19-
20-
object StaticRenderingComparision {
21-
22-
trait TemplateEngine {
23-
def simpleHtml(): Unit
24-
def withVariables(): Unit
25-
def withConditionAndLoop(): Unit
26-
}
27-
28-
val engines = Map(
29-
30-
"levsha" -> new TemplateEngine {
31-
32-
val symbolDsl = new SymbolDsl[Nothing]()
33-
34-
import sharedContent._
35-
import levsha.text.renderHtml
36-
import symbolDsl._
37-
38-
def simpleHtml(): Unit = {
39-
renderHtml {
40-
'body(
41-
'div('class /= "title", "Hello, I'm Cow!"),
42-
'ul('class /= "list",
43-
'li("One"),
44-
'li("Two"),
45-
'li("Three"),
46-
'li("..."),
47-
'li("Moooo")
48-
)
49-
)
50-
}
51-
}
52-
def withVariables(): Unit = {
53-
renderHtml {
54-
'body(
55-
'div('class /= "title", greeting),
56-
'ul('class /= className,
57-
'li("One"),
58-
'li("Two"),
59-
'li("Three"),
60-
'li("..."),
61-
'li("Moooo")
62-
)
63-
)
64-
}
65-
}
66-
def withConditionAndLoop(): Unit = {
67-
renderHtml {
68-
'body(
69-
'div('class /= "title",
70-
if (condition) leftBranch
71-
else rightBranch
72-
),
73-
'ul('class /= className,
74-
items.map(item => 'li(item))
75-
)
76-
)
77-
}
78-
}
79-
},
80-
81-
"scalatags" -> new TemplateEngine {
82-
83-
import sharedContent._
84-
import scalatags.Text.all._
85-
86-
def simpleHtml(): Unit = {
87-
val tags = body(
88-
div(`class` := "title")("Hello, I'm Cow!"),
89-
ul(`class` := "list")(
90-
li("One"),
91-
li("Two"),
92-
li("Three"),
93-
li("..."),
94-
li("Moooo")
95-
)
96-
)
97-
tags.render
98-
}
99-
def withVariables(): Unit = {
100-
val tags = body(
101-
div(`class` := "title")(greeting),
102-
ul(`class` := className)(
103-
li("One"),
104-
li("Two"),
105-
li("Three"),
106-
li("..."),
107-
li("Moooo")
108-
)
109-
)
110-
tags.render
111-
}
112-
def withConditionAndLoop(): Unit = {
113-
val tags = body(
114-
div(`class` := "title")(
115-
if (condition) leftBranch
116-
else rightBranch
117-
),
118-
ul(`class` := className)(
119-
items.map(item => li(item))
120-
)
121-
)
122-
tags.render
123-
}
124-
},
125-
126-
"twirl" -> new TemplateEngine {
127-
import sharedContent._
128-
def simpleHtml(): Unit = html.simple()
129-
def withVariables(): Unit = html.withVariables(greeting, className)
130-
def withConditionAndLoop(): Unit = html.withConditionAndLoop(condition, leftBranch, rightBranch, items)
131-
}
132-
)
133-
134-
// The content should be rendered by template engine
135-
object sharedContent {
136-
137-
val greeting = "Hello, I'm Cow!"
138-
val className = "list"
139-
140-
val condition = true
141-
val leftBranch = "Welcome!"
142-
val rightBranch = "Get off!"
143-
val items = Seq(
144-
"One",
145-
"Two",
146-
"Three",
147-
"...",
148-
"Moooo"
149-
)
150-
}
151-
}
1+
//package levsha.benchmark
2+
//
3+
//import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, State}
4+
//import levsha.dsl.SymbolDsl
5+
//
6+
//@State(Scope.Benchmark)
7+
//class StaticRenderingComparision {
8+
//
9+
// import StaticRenderingComparision.engines
10+
//
11+
// // TODO "beard"
12+
// @Param(Array("levsha", "scalatags", "twirl"))
13+
// var engineName: String = _
14+
//
15+
// @Benchmark def simpleHtml(): Unit = engines(engineName).simpleHtml()
16+
// @Benchmark def withVariables(): Unit = engines(engineName).withVariables()
17+
// @Benchmark def withConditionAndLoop(): Unit = engines(engineName).withConditionAndLoop()
18+
//}
19+
//
20+
//object StaticRenderingComparision {
21+
//
22+
// trait TemplateEngine {
23+
// def simpleHtml(): Unit
24+
// def withVariables(): Unit
25+
// def withConditionAndLoop(): Unit
26+
// }
27+
//
28+
// val engines = Map(
29+
//
30+
// "levsha" -> new TemplateEngine {
31+
//
32+
// val symbolDsl = new SymbolDsl[Nothing]()
33+
//
34+
// import sharedContent._
35+
// import levsha.text.renderHtml
36+
// import symbolDsl._
37+
//
38+
// def simpleHtml(): Unit = {
39+
// renderHtml {
40+
// 'body(
41+
// 'div('class /= "title", "Hello, I'm Cow!"),
42+
// 'ul('class /= "list",
43+
// 'li("One"),
44+
// 'li("Two"),
45+
// 'li("Three"),
46+
// 'li("..."),
47+
// 'li("Moooo")
48+
// )
49+
// )
50+
// }
51+
// }
52+
// def withVariables(): Unit = {
53+
// renderHtml {
54+
// 'body(
55+
// 'div('class /= "title", greeting),
56+
// 'ul('class /= className,
57+
// 'li("One"),
58+
// 'li("Two"),
59+
// 'li("Three"),
60+
// 'li("..."),
61+
// 'li("Moooo")
62+
// )
63+
// )
64+
// }
65+
// }
66+
// def withConditionAndLoop(): Unit = {
67+
// renderHtml {
68+
// 'body(
69+
// 'div('class /= "title",
70+
// if (condition) leftBranch
71+
// else rightBranch
72+
// ),
73+
// 'ul('class /= className,
74+
// items.map(item => 'li(item))
75+
// )
76+
// )
77+
// }
78+
// }
79+
// },
80+
//
81+
// "scalatags" -> new TemplateEngine {
82+
//
83+
// import sharedContent._
84+
// import scalatags.Text.all._
85+
//
86+
// def simpleHtml(): Unit = {
87+
// val tags = body(
88+
// div(`class` := "title")("Hello, I'm Cow!"),
89+
// ul(`class` := "list")(
90+
// li("One"),
91+
// li("Two"),
92+
// li("Three"),
93+
// li("..."),
94+
// li("Moooo")
95+
// )
96+
// )
97+
// tags.render
98+
// }
99+
// def withVariables(): Unit = {
100+
// val tags = body(
101+
// div(`class` := "title")(greeting),
102+
// ul(`class` := className)(
103+
// li("One"),
104+
// li("Two"),
105+
// li("Three"),
106+
// li("..."),
107+
// li("Moooo")
108+
// )
109+
// )
110+
// tags.render
111+
// }
112+
// def withConditionAndLoop(): Unit = {
113+
// val tags = body(
114+
// div(`class` := "title")(
115+
// if (condition) leftBranch
116+
// else rightBranch
117+
// ),
118+
// ul(`class` := className)(
119+
// items.map(item => li(item))
120+
// )
121+
// )
122+
// tags.render
123+
// }
124+
// },
125+
//
126+
// "twirl" -> new TemplateEngine {
127+
// import sharedContent._
128+
// def simpleHtml(): Unit = html.simple()
129+
// def withVariables(): Unit = html.withVariables(greeting, className)
130+
// def withConditionAndLoop(): Unit = html.withConditionAndLoop(condition, leftBranch, rightBranch, items)
131+
// }
132+
// )
133+
//
134+
// // The content should be rendered by template engine
135+
// object sharedContent {
136+
//
137+
// val greeting = "Hello, I'm Cow!"
138+
// val className = "list"
139+
//
140+
// val condition = true
141+
// val leftBranch = "Welcome!"
142+
// val rightBranch = "Get off!"
143+
// val items = Seq(
144+
// "One",
145+
// "Two",
146+
// "Three",
147+
// "...",
148+
// "Moooo"
149+
// )
150+
// }
151+
//}

build.sbt

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,40 @@ val dontPublishSettings = Seq(
2121
)
2222

2323
def additionalUnmanagedSources(cfg: Configuration) = Def.setting {
24-
val isCrossProject = baseDirectory.value.getName match {
25-
case ".js" => true
26-
case ".jvm" => true
27-
case ".native" => true
28-
case _ => false
24+
val baseDir = (cfg / baseDirectory).value
25+
val crossType = baseDir.getName match {
26+
case ".js" => CrossType.Pure
27+
case ".jvm" => CrossType.Pure
28+
case ".native" => CrossType.Pure
29+
case "js" => CrossType.Full
30+
case "jvm" => CrossType.Full
31+
case "native" => CrossType.Full
32+
case _ => CrossType.Dummy
2933
}
30-
val origSourceDir = (cfg / sourceDirectory).value
31-
val sourceDir =
32-
if (isCrossProject) file((cfg / baseDirectory).value.getParent) / "src" / origSourceDir.getName
33-
else origSourceDir
34-
CrossVersion.partialVersion(scalaVersion.value) match {
35-
case Some((3, _)) => Seq(sourceDir / "scala-3")
36-
case Some((2, _)) => Seq(sourceDir / "scala-2")
34+
val versionSpecificDirNames = CrossVersion.partialVersion(scalaVersion.value) match {
35+
case Some((3, _)) => Seq("scala-3")
36+
case Some((2, _)) => Seq("scala-2")
3737
case _ => Seq()
3838
}
39+
val origSourceDir = (cfg / sourceDirectory).value
40+
41+
val result = crossType match {
42+
case CrossType.Pure =>
43+
val sourceDir = origSourceDir.getName
44+
val f = file(baseDir.getParent) / "src" / origSourceDir.getName
45+
versionSpecificDirNames.map(f / _)
46+
case CrossType.Full =>
47+
val f = file(baseDir.getParent) / "shared" / "src" / origSourceDir.getName
48+
versionSpecificDirNames.map(origSourceDir / _) ++ versionSpecificDirNames.map(f / _)
49+
case CrossType.Dummy =>
50+
versionSpecificDirNames.map(origSourceDir / _)
51+
}
52+
result
3953
}
4054

4155
val crossVersionSettings = Seq(
42-
crossScalaVersions := Seq("2.13.6", "2.12.11", "3.0.1"),
43-
scalaVersion := "3.0.1"
56+
crossScalaVersions := Seq("2.13.8", "2.12.15", "3.1.3"),
57+
scalaVersion := "3.1.3"
4458
)
4559

4660
val commonSettings = Seq(
@@ -54,17 +68,17 @@ val commonSettings = Seq(
5468
),
5569
testFrameworks += new TestFramework("utest.runner.Framework"),
5670
libraryDependencies ++= Seq(
57-
"com.lihaoyi" %% "utest" % "0.7.10" % "test",
58-
"org.scalacheck" %% "scalacheck" % "1.15.4" % "test"
71+
"com.lihaoyi" %%% "utest" % "0.7.10" % "test",
72+
"org.scalacheck" %%% "scalacheck" % "1.15.4" % "test"
5973
),
6074
// Add some more source directories
61-
unmanagedSourceDirectories in Compile ++= additionalUnmanagedSources(Compile).value,
62-
unmanagedSourceDirectories in Test ++= additionalUnmanagedSources(Test).value
75+
Compile / unmanagedSourceDirectories ++= additionalUnmanagedSources(Compile).value,
76+
Test/ unmanagedSourceDirectories ++= additionalUnmanagedSources(Test).value
6377
)
6478

6579

6680
lazy val core = crossProject(JSPlatform, JVMPlatform)
67-
.crossType(CrossType.Pure)
81+
.crossType(CrossType.Full)
6882
.enablePlugins(GitVersioning)
6983
.enablePlugins(HeaderPlugin)
7084
.settings(commonSettings: _*)

0 commit comments

Comments
 (0)