jackson-jr icon indicating copy to clipboard operation
jackson-jr copied to clipboard

Afterburner (or Blackbird) with jackson-jr?

Open Macarse opened this issue 9 years ago • 17 comments

As far as I understand afterburner can't be used with jackson-jr.

Is there any plan to "port" afterburner?

Macarse avatar Jul 19 '16 05:07 Macarse

@Macarse I have toyed with the idea as I don't think that is a bad idea at all. I think that should be an optional add-on, similar to how it works with regular Jackson; partly because there is still some additional risk of failures (since it's more elaborate setup with bytecode generation etc), and partly because it just won't work on Android.

I have not worked on anything like this, but I think idea itself is valid and I would love to help if anyone wants to prototype the idea.

cowtowncoder avatar Jul 19 '16 05:07 cowtowncoder

@cowtowncoder afterburner + databind doesn't work on Android?

Macarse avatar Jul 19 '16 05:07 Macarse

Correct: Android bytecode is not Java bytecode but its own thing, and may or may not be dynamically loadable. If it is, then different support library (Afterburner uses asm) could be used to generate Dalvik bytecode for android java vm.

Some of techniques that Afterburner uses would actually work (specifically, use of JsonParser.nextFieldName()), but majority of speedup is from bytecode generation to avoid reflection calls.

cowtowncoder avatar Jul 19 '16 05:07 cowtowncoder

@cowtowncoder I am interested in Android. I was checking another library called LoganSquare: https://github.com/bluelinelabs/LoganSquare There is an issue open mentioning that LoganSquare is not AS fast as it was before: https://github.com/bluelinelabs/LoganSquare/issues/159

Inside their repo they have a comparison of a couple of libraries but jackson-jr is not there. So I wanted to give it a try. I have tried replacing Jackson with Jackson-Jr in my personal branch: https://github.com/Macarse/LoganSquare/tree/macarse/jacksonJr but it just doesn't work :(

Is there a way to see logs?

Macarse avatar Jul 19 '16 22:07 Macarse

@Macarse logs of... ? Neither Jackson nor jackson-jr logs anything

FWIW LoganSquare does use streaming parer/generator from jackson-core, so the suggestion by someone that it is much more likely that new version helps with regular Jackson databind to get closer, than that LS is slowed down. Android reflection performance, specifically, was abysmally bad before, so if that is sped up, difference would be big.

Still would be interesting to see jackson-jr; on JavaSE jr has performance similar to regular jackson. And with version 2.8 can use fields, not just getter/setter methods.

cowtowncoder avatar Jul 19 '16 22:07 cowtowncoder

@cowtowncoder oh interesting. How do you usually figure out what's wrong?

The code is serializing with:

String ret = JSON.std.asString(response);

Logs show that the String output is:{} and I can't find what's wrong :(

Macarse avatar Jul 19 '16 23:07 Macarse

@Macarse what is the class like? It would first sound like there were no public getters available on that object -- jackson-jr versions before 2.8.0 required getters. It is also not an error if no properties are found (unlike default settings with Jackson).

cowtowncoder avatar Jul 19 '16 23:07 cowtowncoder

@cowtowncoder wait, what?

I am using jackson-jr in my work project and I am using it without getters and setters. Just public fields.

Macarse avatar Jul 19 '16 23:07 Macarse

@cowtowncoder ok, I am clueless. Adding getters and setters fixed the LoganSquare Demo. I will update my code.

How come my model works without getters and setters?

Macarse avatar Jul 19 '16 23:07 Macarse

btw, this is the result of running my branch in a nexus 6p with developer preview 4.

screenshot_20160719-165146

screenshot_20160719-165212

Macarse avatar Jul 20 '16 00:07 Macarse

Cool. So, on fields -- version 2.8.0 DOES support use of simple public fields. Older versions (up 2.7) do NOT. So it depends on version. Support for fields was added since Android developers mentioned that there are reasons for wanting to avoid use of fields.

Interesting numbers; clearly Moshi has been geared at Android use as its numbers are better than GSON here, which is different from J2SE where GSON seems to be faster.

cowtowncoder avatar Jul 20 '16 03:07 cowtowncoder

I found my issue, after cleaning the build my code stop working. Apparently I started using 2.8 and changed it to 2.7.x but the dependency was not updated.

@cowtowncoder do you maintain a changelog? I can't find any doc which says 2.8 supports fields and 2.7 does not. I would also like to know if 2.8.1 is prod ready.

Macarse avatar Jul 20 '16 16:07 Macarse

Yes, changelog is under release-notes/VERSION, and entry for field addition is #26. In addition, Jackson release notes:

https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8

list this change (although list of all changes is sometimes incomplete; modules keep actual changes in release-notes/VERSION and those should be complete change lists).

2.8.1 is now released.

cowtowncoder avatar Jul 20 '16 17:07 cowtowncoder

@cowtowncoder thanks. since I am only going to use USE_FIELDS, should I turn off other features? for example USE_IS_GETTERS.

Macarse avatar Jul 21 '16 18:07 Macarse

@Macarse yes, you may want to do that; if it's left on, getter/setter is used instead of field if one exists, otherwise field is used. So if you never plan on using getters, turn them off; ditto for setters.

cowtowncoder avatar Jul 21 '16 22:07 cowtowncoder

What would be required to add Afterburner style support? Can this still be evaluated?

re-thc avatar May 30 '18 14:05 re-thc

@hc-codersatlas If anyone wants to implement it, I'd be happy to help. I do not have any extra time to work on this personally. But then again, mr-bean came as external contribution, and then served as basis of Afterburner.

But basically jackson-jr does not have any extension points to support this yet. Adding extension points might not be superbly difficult, and it might even make sense to add support for ability to map abstract types to concrete more generally (since the two parts are related in Jackson).

cowtowncoder avatar May 30 '18 17:05 cowtowncoder