glaforge/gaelyk — Issue #96: Manual Coercion Performance Seems Pretty Bad
Author: codeconsole
Created: 2011-11-23 22:04:13+00:00
State: open

Manual coercion seems to be performing pretty bad.

Example:

import com.google.appengine.api.datastore.Entity
import groovyx.gaelyk.GaelykCategory
import org.springframework.util.StopWatch
import groovyx.gaelyk.datastore.Key
import groovy.transform.Canonical

def watch = new StopWatch("Coercion")

@Canonical
class Person {
@Key Long id
String name
}

use (GaelykCategory) {
watch.start("build")
def entities = []
for (long i = 1; i < 200; i++) {
Entity entity = new Entity("Person", i)
entity.name = "Person ${i}"
entities << entity
}
watch.stop()
watch.start("manual coercion")
entities.each {
it as Person
}
watch.stop()
watch.start("construction")
entities.each {
new Person(it.id, it.name)
}
watch.stop()
System.out.println watch.toString()
}

result:

StopWatch 'Coercion': running time (millis) = 576; [build] took 20 = 3%; [manual coercion] took 530 = 92%; [construction] took 26 = 5%