-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
JsonStringEncoder should take CharSequence parameters #265
Comments
I can have a look at this. The main concern would be backwards compatibility; change of type here would be gnarly binary-incompatibility (esp. since it's source compatible), but addition of an alternate method could work. But beyond this, performance via interface is probably inferior, so the first thing encoder would most likely do would be to use If I find time I can do a micro-benchmark to see if my guess is correct wrt speed of |
This should only be done if it can be done without using I am quite sure it can be done without using |
@mikaelstaldal Functionally speaking it can certainly be done, but the point is to keep performance high. Changing access from Jackson core itself has no use for sources other than Beyond performance test showing there is no measurable difference, what would be needed would be new method(s) to avoid backwards-compatibility breakage, and leaving existing method in place. |
Yes, I request this for external use. Specifically to be able to pass in a |
@mikaelstaldal Makes sense. Actually I think that despite duplication of code that is unfortunate in general, perhaps just cut'n pasting method with new name, more generic type, would be the way to go here? I'd merge such a PR. |
Does the method need to have a new name? Can't we rely on overloading? |
@mikaelstaldal Unfortunately no: this is changing method signature in bytecode, and then any code compiled against older version will fail on class loading phase. This is unfortunate as compiler would not have problem with it. At the same time, it goes around any perf implications as well. So: source compatible, but binary incompatible version could break any old code that used the method. While it's not necessarily while used outside of |
OK, updated my PR. |
Fixed as per merged #266 |
Nice. However, there is one problem left. Both the new and the old method will inevitably allocate objects due to the way |
@mikaelstaldal Multiple reasons, from allocation strategy (StringBuilder always does double-up resizing, which is costly for longer content), to reuse (TextBuffer can recycle its underlying buffering using ThreadLocal) and more efficient building (direct sets on So it is in many ways just a customized StringBuilder crafted for specific uses Jackson has (althought its heritage is from Woodstox XML processor). |
Would it be possible to avoid object allocations in each call to |
@mikaelstaldal as far as I recall that should only really allocate |
It does an allocation here:
|
@mikaelstaldal Yes, if you ask for contents as an exact size buffer you can do that instead of creating a String (which would also allocate an underlying So I am not quite sure how else to reduce allocations. The only remaining additional thing would be to add a method that would copy contents to caller-provided |
I found out an elegant way to do it: #268 |
I tried 2.8.0-SNAPSHOT, and it works fine for me. |
When do you plan to release the next version of Jackson (with this included)? |
@mikaelstaldal that will take a while, probably couple of months. First release candidates might go out in late May or early June, which would follow loose "2 minor releases per year" schedule. In the meantime perhaps you can cut'n paste class in your source code, and remove when 2.8 is out? |
Yes I could do that, given that there are no copyright issues. The project I am working on is Apache Log4j. If I understand it correctly, Jackson uses the same license as we do (Apache 2.0)? |
I could put in a comment saying:
|
@mikaelstaldal correct, Jackson is Apache License 2.0, and that comment would work just fine as attribution. |
It would be useful if the public methods in
com.fasterxml.jackson.core.io.JsonStringEncoder
declare its input parameter asCharSequence
rather thanString
.To me, it seems to be trivial to fix since the code only uses methods on the input parameter which are in
CharSequence
(length
andcharAt
).The text was updated successfully, but these errors were encountered: