Quantcast
Channel: Sleepless Dev
Viewing all articles
Browse latest Browse all 217

Boon News 0.11 is out

$
0
0

News in Boon

Boon 0.11 is out. Thanks Stephane Landelle! Boon JSON parser still faster than GSON and Jackson. Up to 3x faster.
Added lightweight JSON DI container that supports @Inject, @PostConstruct, @Required, @Autowire, and more.
publicclassCoffeeAppimplementsRunnable{
@Inject
CoffeeMakercoffeeMaker;
@Inject
Coffeecoffee;
@Inject
Sugarsugar;
@Inject
Baconbacon;
@Inject
@Named("brown")
BaconbrownBacon;
JSON support now support @JsonProperty, @JsonView, and more. Learn more here: http://rick-hightower.blogspot.com/2014/01/boon-json-in-five-minutes-faster-json.html
Wrote invoker library to work JSON posts. It is a better way to do REST and WebSocket with Boon.
Wrote functional library based on work that I did with EasyJava.
You can do reflection based filters or regular Predicate filters.
List<Employee>list=list(newEmployee("Bob"),newEmployee("Sally"));
setListProperty(list,"salary",200);
list.addAll(Lists.list(newEmployee("Rick"),newEmployee("Joe")));

//Reflection
List<Employee>filtered=filterBy(list,newObject(){
booleant(Employeee){returne.salary>150;}
});


...

//Predicate based
List<Employee>filtered=filterBy(list,newPredicate<Employee>(){
@Override
publicbooleantest(Employeeinput){
returninput.salary>150;
}
});

My goal is take some previous work that I did with invoke dynamic and make the reflection based predicate faster than the Predicate interface.
You can also filter with static or non-static methods
List<Employee>filtered=filterBy(list,ListsTest.class,"filterBySalary");
...

List<Employee>filtered=filterBy(list,this,"filterBySalaryMethod");
Also don't forget that Boon ships with a full in-memory query engine that is actually faster than the predicate based filters.
List<Employee>filtered=query(list,gt("salary",150));
Learn more about the Boon data repo here:
But I digress back to functional framework:
The usual suspects are here:
...

//Reflection Mapper -- Convert Employee object into HRObject
List<HRObject>wrap=(List<HRObject>)mapBy(list,newObject(){
HRObjecthr(Employeee){returnnewHRObject(e);}
});

...
//Reflection static or non-static methods
List<HRObject>wrap=(List<HRObject>)mapBy(list,ListsTest.class,"createHRO");

List<HRObject>wrap=(List<HRObject>)mapBy(list,this,"createHROMethod");

...
//Constructor mapping
List<Employee>list=list(newEmployee("Bob"),newEmployee("Sally"));
List<HRObject>wrap=wrap(HRObject.class,list);
...


//
List<Employee>list=list(newEmployee("Bob"),newEmployee("Sally"));
List<HRObject>wrap=mapBy(list,newFunction<Employee,HRObject>(){
@Override
publicHRObjectapply(Employeeemployee){
returnnewHRObject(employee);
}
});


Here is one you don't see much:
@Test
publicvoidreduce(){
longsum=(int)reduceBy(Lists.list(1,2,3,4,5,6,7,8),newObject(){
intsum(ints,intb){returns+b;}
});

booleanok=sum==36||die();
puts(sum);



sum=(long)reduceBy(newInteger[]{1,2,3,4,5,6,7,8},newObject(){
longsum(longs,intb){returns+b;}
});

ok&=sum==36||die();



sum=(long)reduceBy(newint[]{1,2,3,4,5,6,7,8},newObject(){
longsum(longs,intb){returns+b;}
});

ok&=sum==36||die();


sum=(long)reduceBy(Lists.list(1,2,3,4,5,6,7,8),newReducer<Integer,Integer>(){
@Override
publicIntegerapply(Integersum,Integerv){
returnsum==null?v:sum+v;
}
}).longValue();


}

EasyJava had currying and all sorts of wild stuff, so I might port some of that here. I might not. Let me know.
String Parsing.... Boon has really fast String parsing about 2x speed what you could do with JDK readily, and a smaller GC foot print so instead of this:
staticPatternnewLine=Pattern.compile("(\n|\r)");
...
inti=0;
String[]splitLines=newLine.split(str);
String[]stats;

for(Stringline:splitLines){
stats=line.split(",");
i+=Integer.parseInt(stats[1]);
}
returni;
You can do this (for 2x speed and a lot less GC overhead):
inti=0;
String[]splitLines=splitLines(str);
String[]stats;

for(Stringline:splitLines){
stats=splitComma(line);
i+=Integer.parseInt(stats[1]);
}
returni;
Or even this (2.5x faster and even less GC overhead):
char[]chars=toCharArray(csv);
inti=0;
char[][]splitLines=splitLines(chars);
char[][]stats;

for(char[]line:splitLines){
stats=splitComma(line);
i+=parseInt(stats[1]);
}
returni;
Boon is not just fast. Boon is a flame throwing, turbo-charged, get-out-of-the-way-I-am-coming-in, speed-demon that sips GC, and makes CPUs and virtual cores wish they went into dentistry.



Viewing all articles
Browse latest Browse all 217

Trending Articles