Skip to content

Instantly share code, notes, and snippets.

View VladUreche's full-sized avatar

Vlad Ureche VladUreche

View GitHub Profile
@VladUreche
VladUreche / Scala LabelDefs
Created May 16, 2012 11:45
Question about how the Scala Compiler generates LabelDefs
$ cat test.scala
trait Foo[A] {
final def bar(a:A):A = bar(a)
}
$ scalac -Xprint:tailcalls test.scala
[[syntax trees at end of tailcalls]] // test.scala
package <empty>#4 {
abstract trait Foo#6[A#7308 >: Nothing#3704 <: Any#3703] extends Object#1785 {
...

Miniboxing Logo

Miniboxing - Reverse Example

This is an example of using the miniboxing plugin in the Scala interpreter. For the benchmark, we reverse a 10M integer array, and compare the performance of the generic version and the miniboxed version.

You get 4-9x speedups by adding a single @miniboxed annotation:

scala> def reverse_gen[T](array: Array[T]): Unit = ...
@VladUreche
VladUreche / gist:8396624
Created January 13, 2014 08:39
Scaladoc tutorial for docs.scala-lang.org, in a pitiful state
# Scaladoc Developer Guide
## Introduction
Scaladoc is the tool that enables developers to automatically generate documentation for their Scala (and Java) projects. It is Scala's equivalent of the widely-used Javadoc tool. This means that Javadoc (and even doxygen) users will be familiar with Scaladoc from day 1: for them, it is most beneficial to check out the Scaladoc/Javadoc comparison tables and if necessary, skim through this document to understand specific features.
The rest of this tutorial is aimed at developers new to Scaladoc and other similar tools. It assumes a basic understanding of the Scala language, which is necessary to follow the examples given throughout the tutorial. For the user perspective on the Scaladoc-generated documentation, such as finding a class, understanding the page layout, navigating through diagrams, please refer to the Scaladoc User Guide.
The tutorial will start by a short motivation and then will explain the main concept in Scaladoc: the doc comment.
### Why document?
$ ls
A.scala B.scala
$ cat A.scala
class A[@specialized T](t: T)
$ scalac A.scala
$ cat B.scala
object Test extends App {
$ cat C.scala
class C[@specialized T](t: T)
class D[@specialized T](t: T) extends C[T](t)
$ scalac C.scala
C.scala:2: warning: class C must be a trait. Specialized version of class D will inherit generic C[Boolean]
class D[@specialized T](t: T) extends C[T](t)
^
one warning found
@VladUreche
VladUreche / miniboxing-challenge-gsoc14.md
Last active August 29, 2015 13:57
Miniboxing Challenge

GSOC 2014 Challenge

####Fix the following bug miniboxing/miniboxing-plugin#63.

Short Explanation

In miniboxing, the optimized data representation stores values encoded on a long integer. Still, whenever the program needs to perform operations on the actual data, it is transformed to its original type.

For example, when doing the following operation:

@VladUreche
VladUreche / infer-issue
Created June 10, 2014 22:00
Type inference issue
$ cat infer.scala
package p
class ann extends annotation.StaticAnnotation with annotation.TypeConstraint
class Seq[T] {
def map[U](f: T => U): Seq[U] = ???
}
object Test {
@VladUreche
VladUreche / patmat.scala
Created August 25, 2014 14:50
Pattern matcher + ClassTags => incorrect trees
$ cat test.scala
class Worker {
def receive[Id: scala.reflect.ClassTag] =
(x: Any) => x match {
case source: Id =>
val src: Id = source
}
}
@VladUreche
VladUreche / bug188-details.md
Last active August 29, 2015 14:17
JVM Debug output for miniboxing bug #188

Bug: miniboxing/miniboxing-plugin#188

For the record, here's the full VM output (the flags I used there are only available in debug builds of the JVM, which, although they are also dead slow, make the same inlining decisions as the normal VM):

Full output

Miniboxed:

$ mb-scala -J-XX:+PrintCompilation -J-XX:+PrintInlining -J-XX:+TraceDeoptimization brique.Test
Picked up _JAVA_OPTIONS: -Xms2g -Xmx2g -Xss4m -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=256m -XX:PermSize=256m -XX:+TieredCompilation -XX:+UseNUMA
@VladUreche
VladUreche / bug188-gc.md
Last active August 29, 2015 14:17
JVM GC output for minboxing bug #188

Bug: miniboxing/miniboxing-plugin#188

Below are the full outputs. But let's take a typical loop in the generic code:

restarting timing
[GC 631036K->45244K(2043392K), 0.0217070 secs]
[GC 636604K->50652K(2049024K), 0.0495480 secs]
[GC 649692K->40220K(2045952K), 0.0023550 secs]
805 ms for 100 iterations