eclipse-ee4j / jaxb-fi

Apache License 2.0
8 stars 10 forks source link

[PATCH] Use StringBuilder instead of StringBuffer for performance gains #48

Closed Tomas-Kraus closed 9 months ago

Tomas-Kraus commented 11 years ago

The current FastInfoset code uses the StringBuffer class for building strings.

The StringBuffer class is synchronised, which doesn't seem to be needed in this case, as the involved decoder, parser and various algorithm classes aren't meant to be thread-safe anyway and their use depends on external synchronization (correct me if I'm wrong).

Since the FastInfoset project requires Java >= 1.5 (according to its pom.xml), we can use the StringBuilder class which has an almost identical API and which by itself doesn't involve synchronization. This should give small performance gains.

Affected Versions

[1.2.12]

Tomas-Kraus commented 5 years ago
Tomas-Kraus commented 11 years ago

@glassfishrobot Commented Reported by olo

Tomas-Kraus commented 11 years ago

@glassfishrobot Commented olo said: I don't seem to have permissions required to attach a patch in this JIRA, so I've published a full FastInfoset repo on GitHub, with the change covered by this issue in this commit:

https://github.com/aadamowski/fi.java.net/commit/a5577ab508af495062a52eda1b374826459117a9

Tomas-Kraus commented 11 years ago

@glassfishrobot Commented snajper said: Hi, thanks for looking into this. I commited some small changes that are expected to be safe, however most of these are api changes and would require somewhat more safer approach.

Tomas-Kraus commented 11 years ago

@glassfishrobot Commented olo said: If a concrete class is specified as an element of the API on public and protected method signatures, there's no really safe approach.

Wouldn't it be a good idea to make a major version number increment and clean this API up by substituting StringBuffer class with an appropriate interface (Appendable?) in those signatures?

Tomas-Kraus commented 11 years ago

@glassfishrobot Commented olo said: BTW, the changes that I'd envision would be something like this:

diff --git a/code/fastinfoset/src/main/java/org/jvnet/fastinfoset/EncodingAlgorithm.java b/code/fastinfoset/src/main/java/org/jvnet/fastinfoset/EncodingAlgorithm.java
index b7a016b..667efe3 100755
--- a/code/fastinfoset/src/main/java/org/jvnet/fastinfoset/EncodingAlgorithm.java
+++ b/code/fastinfoset/src/main/java/org/jvnet/fastinfoset/EncodingAlgorithm.java
@@ -33,6 +33,6 @@ public interface EncodingAlgorithm {

     public Object convertFromCharacters(char[] ch, int start, int length) throws EncodingAlgorithmException;

-    public void convertToCharacters(Object data, StringBuilder s) throws EncodingAlgorithmException;
+    public <T extends Appendable & CharSequence> void convertToCharacters(Object data, T s) throws EncodingAlgorithmException;

 }
Tomas-Kraus commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA FI-48