diff options
author | Jesse Wilson <jessewilson@google.com> | 2010-11-14 12:01:08 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2010-11-16 11:45:05 -0800 |
commit | a78c2aac2a73f001aa00971adfae90af4d6726fb (patch) | |
tree | ee9ac7b9fdc4f92cfe8823d37a56c3f10521cf9b /xml/src | |
parent | 4ab2cec301baf9704b1235aa50b544e8d7f53124 (diff) | |
download | libcore-a78c2aac2a73f001aa00971adfae90af4d6726fb.zip libcore-a78c2aac2a73f001aa00971adfae90af4d6726fb.tar.gz libcore-a78c2aac2a73f001aa00971adfae90af4d6726fb.tar.bz2 |
Add interning to KxmlPullParser.
Adding just a small interning pool improves performance even further.
Combined with the first round of optimizations, total improvement for
three large files is 51% 56% and 42%. Performance on a small file
improved 3%. When interning is checked in, Kxml will be significantly
faster than Expat's pull parser for everything but very small files.
/sdcard/xml/com.amazon.mp3.meta /sdcard/xml/com.cooliris.picasa /sdcard/xml/com.rhapsody.Deauth /sdcard/xml/com.snoggdoggler.r
benchmark run us linear runtime % us linear runtime % us linear runtime % us linear runtime %
Dom baseline / master 210,256 ============================== 184% 53,227 ============================== 171% 2,183 ============================== 151% 164,708 ============================= 200%
Dom first optimizations 174,580 ======================== 153% 40,964 ======================= 132% 1,968 =========================== 136% 130,814 ======================= 159%
Dom new interning 163,366 ======================= 143% 35,736 ==================== 115% 2,116 ============================= 147% 121,870 ====================== 148%
ExpatPull baseline / master 130,078 ================== 114% 21,700 ============ 70% 759 ========== 53% 85,578 =============== 104%
ExpatPull first optimizations 129,776 ================== 114% 21,621 ============ 70% 734 ========== 51% 86,799 =============== 105%
ExpatPull new interning 130,971 ================== 115% 21,627 ============ 70% 723 ========= 50% 86,555 =============== 105%
KxmlPull baseline / master 114,317 ================ 100% 31,040 ================= 100% 1,443 =================== 100% 82,478 =============== 100%
KxmlPull first optimizations 88,716 ============ 78% 20,578 =========== 66% 1,560 ===================== 108% 58,567 ========== 71%
KxmlPull new interning 55,773 ======= 49% 13,692 ======= 44% 1,394 =================== 97% 48,068 ======== 58%
http://b/3090550
Change-Id: I4515546abbbcf940de7be22f26925c4334e59146
Diffstat (limited to 'xml/src')
-rw-r--r-- | xml/src/main/java/org/kxml2/io/KXmlParser.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/xml/src/main/java/org/kxml2/io/KXmlParser.java b/xml/src/main/java/org/kxml2/io/KXmlParser.java index 9ca555b..9c20e0d 100644 --- a/xml/src/main/java/org/kxml2/io/KXmlParser.java +++ b/xml/src/main/java/org/kxml2/io/KXmlParser.java @@ -28,6 +28,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.util.HashMap; import java.util.Map; +import libcore.internal.StringPool; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -106,6 +107,8 @@ public class KXmlParser implements XmlPullParser { private boolean unresolved; private boolean token; + public final StringPool stringPool = new StringPool(); + /** * Retains namespace attributes like {@code xmlns="http://foo"} or {@code xmlns:foo="http:foo"} * in pulled elements. Most applications will only be interested in the effective namespaces of @@ -403,7 +406,7 @@ public class KXmlParser implements XmlPullParser { if (!returnText) { return null; } else if (result == null) { - return new String(buffer, start, end - start); + return stringPool.get(buffer, start, end - start); } else { result.append(buffer, start, end - start); return result.toString(); @@ -495,7 +498,7 @@ public class KXmlParser implements XmlPullParser { if (assignText) { if (result == null) { - text = new String(buffer, start, position - start - 1); // omit the '>' + text = stringPool.get(buffer, start, position - start - 1); // omit the '>' } else { result.append(buffer, start, position - start - 1); // omit the '>' text = result.toString(); @@ -882,7 +885,7 @@ public class KXmlParser implements XmlPullParser { } if (result == null) { - return new String(buffer, start, position - start); + return stringPool.get(buffer, start, position - start); } else { result.append(buffer, start, position - start); return result.toString(); @@ -1016,7 +1019,7 @@ public class KXmlParser implements XmlPullParser { // we encountered a non-name character. done! if (result == null) { - return new String(buffer, start, position - start); + return stringPool.get(buffer, start, position - start); } else { result.append(buffer, start, position - start); return result.toString(); |