Skip to content

Commit 096a24e

Browse files
committed
Merge branch 'release/0.5.2'
2 parents fa8de69 + 6015528 commit 096a24e

File tree

6 files changed

+78
-10
lines changed

6 files changed

+78
-10
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: scala
2+
sudo: false
23
scala:
34
- 2.10.4
45
- 2.11.2

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# chill #
22

3+
### 0.5.2 ###
4+
* Use new Travis CI infrastructure #210
5+
* Optimizations for ConfiguredInstantiator. #213
6+
* Upgrade to algebird 0.9.0, bijection 0.7.2, scala 2.11.5 #214
7+
38
### 0.5.1
49
* reverse Config contains logic: https://github.com/twitter/chill/pull/205
510
* fix setConf: https://github.com/twitter/chill/pull/204

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ object is created.
139139

140140
## Community and Documentation
141141

142+
This, and all [github.com/twitter](https://github.com/twitter) projects, are under the [Twitter Open Source Code of Conduct](https://engineering.twitter.com/opensource/code-of-conduct). Additionally, see the [Typelevel Code of Conduct](http://typelevel.org/conduct) for specific examples of harassing behavior that are not tolerated.
143+
142144
To learn more and find links to tutorials and information around the web, check out the [Chill Wiki](https://github.com/twitter/chill/wiki).
143145

144146
The latest ScalaDocs are hosted on Chill's [Github Project Page](http://twitter.github.io/chill).
@@ -147,7 +149,7 @@ Discussion occurs primarily on the [Chill mailing list](https://groups.google.co
147149

148150
## Maven
149151

150-
Chill modules are available on Maven Central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.5.1` and each scala project is published for `2.10` and `2.11`. Search [search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cchill) when in doubt.
152+
Chill modules are available on Maven Central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.5.2` and each scala project is published for `2.10` and `2.11`. Search [search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cchill) when in doubt.
151153

152154
## Authors
153155

chill-java/src/main/java/com/twitter/chill/config/ConfiguredInstantiator.java

+43-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public ConfiguredInstantiator(Config conf) throws ConfigurationException {
5252
delegate = new KryoInstantiator();
5353
}
5454
else {
55-
String[] parts = key.split(":");
56-
if(parts.length != 1 && parts.length != 2) {
55+
String[] parts = fastSplitKey(key);
56+
if(parts == null) {
5757
throw new ConfigurationException("Invalid Config Key: " + conf.get(KEY));
5858
}
5959
KryoInstantiator reflected = null;
@@ -63,7 +63,7 @@ public ConfiguredInstantiator(Config conf) throws ConfigurationException {
6363
}
6464

6565
if(parts.length == 2) {
66-
delegate = deserialize(reflected.newKryo(), parts[1]);
66+
delegate = fastDeserialize(reflected.newKryo(), parts[1]);
6767
if(null == delegate) {
6868
throw new ConfigurationException("Null delegate from: " + parts[1]);
6969
}
@@ -149,4 +149,44 @@ protected static String serialize(Kryo k, KryoInstantiator ki) {
149149
k.writeClassAndObject(out, ki);
150150
return Base64.encodeBytes(out.toBytes());
151151
}
152+
153+
/** Simple class to hold the cached copy of the latest kryo instantiator.
154+
* As well as its corresponding base64 encoded data.
155+
*/
156+
private static class CachedKryoInstantiator {
157+
public final KryoInstantiator kryoInstantiator;
158+
public final String base64Value;
159+
public CachedKryoInstantiator(KryoInstantiator ki, String bv) {
160+
kryoInstantiator = ki;
161+
base64Value = bv;
162+
}
163+
}
164+
165+
private static CachedKryoInstantiator cachedKryoInstantiator = null;
166+
167+
private static synchronized KryoInstantiator fastDeserialize(Kryo k, String base64Value) throws ConfigurationException {
168+
if(cachedKryoInstantiator == null || !cachedKryoInstantiator.base64Value.equals(base64Value)) {
169+
cachedKryoInstantiator = new CachedKryoInstantiator(deserialize(k, base64Value), base64Value);
170+
}
171+
return cachedKryoInstantiator.kryoInstantiator;
172+
}
173+
174+
/** Java's string split is very expensive due to regexes.
175+
* Implement our own simple version instead.
176+
*/
177+
public static String[] fastSplitKey(String key) {
178+
int i = key.indexOf(':');
179+
if(-1 == i) {
180+
return new String[]{key};
181+
}
182+
else {
183+
int j = key.indexOf(':', i+1);
184+
if (-1 != j) {
185+
return null;
186+
}
187+
else {
188+
return new String[]{key.substring(0, i), key.substring(i+1)};
189+
}
190+
}
191+
}
152192
}

chill-java/src/test/scala/com/twitter/chill/config/ConfiguredInstantiatorTest.scala

+20
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ limitations under the License.
1616

1717
package com.twitter.chill.config
1818

19+
import org.scalacheck.Prop.forAll
20+
import org.scalacheck.Properties
1921
import org.scalatest._
2022

2123
import com.twitter.chill._
2224
import com.esotericsoftware.kryo.Kryo
2325

2426
class TestInst extends KryoInstantiator { override def newKryo = new Kryo }
27+
class TestInstTwo extends KryoInstantiator { override def newKryo = new Kryo }
2528

2629
class ReflectingInstantiatorTest extends WordSpec with Matchers {
2730
"A ConfiguredInstantiator" should {
@@ -38,6 +41,23 @@ class ReflectingInstantiatorTest extends WordSpec with Matchers {
3841
val cci = new ConfiguredInstantiator(conf)
3942
// Here is the only assert:
4043
cci.getDelegate.getClass should equal(classOf[TestInst])
44+
// Verify that caching is working:
45+
val cci2 = new ConfiguredInstantiator(conf)
46+
cci.getDelegate should equal(cci2.getDelegate)
47+
// Set a new serialized and verify caching is still correct:
48+
ConfiguredInstantiator.setSerialized(conf, new TestInstTwo)
49+
val cci3 = new ConfiguredInstantiator(conf)
50+
cci3.getDelegate.getClass should equal(classOf[TestInstTwo])
51+
cci3.getDelegate should not equal (cci2.getDelegate)
52+
}
53+
}
54+
}
55+
56+
object ConfiguredInstantiatorProperties extends Properties("ConfiguredInstantiator") {
57+
property("properly split keys") = forAll { (str: String) =>
58+
ConfiguredInstantiator.fastSplitKey(str) match {
59+
case null => str.split(":").length > 2
60+
case success => success.mkString(":") == str
4161
}
4262
}
4363
}

project/Build.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ object ChillBuild extends Build {
2020

2121
val sharedSettings = Project.defaultSettings ++ mimaDefaultSettings ++ scalariformSettings ++ Seq(
2222

23-
version := "0.5.1",
23+
version := "0.5.2",
2424
organization := "com.twitter",
2525
scalaVersion := "2.10.4",
26-
crossScalaVersions := Seq("2.10.4", "2.11.2"),
26+
crossScalaVersions := Seq("2.10.4", "2.11.5"),
2727
scalacOptions ++= Seq("-unchecked", "-deprecation"),
2828
ScalariformKeys.preferences := formattingPreferences,
2929

@@ -126,7 +126,7 @@ object ChillBuild extends Build {
126126
.filterNot(unreleasedModules.contains(_))
127127
.map { s =>
128128
val suffix = if (javaOnly.contains(s)) "" else "_2.10"
129-
"com.twitter" % ("chill-" + s + suffix) % "0.5.1"
129+
"com.twitter" % ("chill-" + s + suffix) % "0.5.2"
130130
}
131131

132132
def module(name: String) = {
@@ -158,7 +158,7 @@ object ChillBuild extends Build {
158158

159159
lazy val chillBijection = module("bijection").settings(
160160
libraryDependencies ++= Seq(
161-
"com.twitter" %% "bijection-core" % "0.7.0"
161+
"com.twitter" %% "bijection-core" % "0.7.2"
162162
)
163163
).dependsOn(chill % "test->test;compile->compile")
164164

@@ -226,14 +226,14 @@ object ChillBuild extends Build {
226226

227227
lazy val chillAvro = module("avro").settings(
228228
libraryDependencies ++= Seq(
229-
"com.twitter" %% "bijection-avro" % "0.7.0",
229+
"com.twitter" %% "bijection-avro" % "0.7.2",
230230
"junit" % "junit" % "4.5" % "test"
231231
)
232232
).dependsOn(chill,chillJava, chillBijection)
233233

234234
lazy val chillAlgebird = module("algebird").settings(
235235
libraryDependencies ++= Seq(
236-
"com.twitter" %% "algebird-core" % "0.8.0"
236+
"com.twitter" %% "algebird-core" % "0.9.0"
237237
)
238238
).dependsOn(chill)
239239
}

0 commit comments

Comments
 (0)