-
Notifications
You must be signed in to change notification settings - Fork 707
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
Cache boxed classes #1501
Cache boxed classes #1501
Changes from 1 commit
158a41e
7fa40a3
d142a36
509e132
489236f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ trait OrderedSerialization[T] extends Ordering[T] with Serialization[T] { | |
def compareBinary(a: InputStream, b: InputStream): OrderedSerialization.Result | ||
} | ||
|
||
/** | ||
* In order to cache OrderedSerializations having equality and hashes can be useful. | ||
* Extend this trait when those two properties can be satisfied | ||
*/ | ||
trait EquivOrderedSerialization[T] extends OrderedSerialization[T] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about just |
||
|
||
object OrderedSerialization { | ||
/** | ||
* Represents the result of a comparison that might fail due | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,10 +228,12 @@ object TreeOrderedBuf { | |
val lenB = freshT("lenB") | ||
|
||
t.ctx.Expr[OrderedSerialization[T]](q""" | ||
new _root_.com.twitter.scalding.serialization.OrderedSerialization[$T] { | ||
new _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.MacroEqualityOrderedSerialization[$T] { | ||
// Ensure macro hygene for Option/Some/None | ||
import _root_.scala.{Option, Some, None} | ||
|
||
override val uniqueId: String = ${T.tpe.toString} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the full type? Can you test for that in the test? I have anxiety about it not being the fully qualified name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see an easy way to say it must be the FQN, it seems in manual testing to be the FQN when its not a built in type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a test in there that for a custom type it is the FQN now |
||
|
||
private[this] var lengthCalculationAttempts: Long = 0L | ||
private[this] var couldNotLenCalc: Long = 0L | ||
private[this] var skipLenCalc: Boolean = false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2014 Twitter, Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. back dating it? :) |
||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers | ||
|
||
import com.twitter.scalding.serialization.EquivOrderedSerialization | ||
|
||
object MacroEqualityOrderedSerialization { | ||
private val seed = "MacroEqualityOrderedSerialization".hashCode | ||
} | ||
|
||
abstract class MacroEqualityOrderedSerialization[T] extends EquivOrderedSerialization[T] { | ||
def uniqueId: String | ||
override def hashCode = MacroEqualityOrderedSerialization.seed ^ uniqueId.hashCode | ||
override def equals(other: Any): Boolean = other match { | ||
case o: MacroEqualityOrderedSerialization[_] => o.uniqueId == uniqueId | ||
case _ => false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep this called
next
for binary compat and have adef nextCached(o: EquivSerialization[_]): ...
which handles the cache logic?