Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 13F14200CE6 for ; Thu, 17 Aug 2017 00:57:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 120D116922A; Wed, 16 Aug 2017 22:57:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 58596169216 for ; Thu, 17 Aug 2017 00:57:07 +0200 (CEST) Received: (qmail 27700 invoked by uid 500); 16 Aug 2017 22:57:05 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 27687 invoked by uid 99); 16 Aug 2017 22:57:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Aug 2017 22:57:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 3512F1A19E4 for ; Wed, 16 Aug 2017 22:57:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id NIy8w2TuPKlC for ; Wed, 16 Aug 2017 22:57:04 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 697245F5B3 for ; Wed, 16 Aug 2017 22:57:03 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 8EE71E045B for ; Wed, 16 Aug 2017 22:57:02 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 12B3D2537F for ; Wed, 16 Aug 2017 22:57:01 +0000 (UTC) Date: Wed, 16 Aug 2017 22:57:01 +0000 (UTC) From: "Tom Howard (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (TEXT-99) Performance Degradation for Escaping JSON MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 16 Aug 2017 22:57:08 -0000 [ https://issues.apache.org/jira/browse/TEXT-99?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16129572#comment-16129572 ] Tom Howard commented on TEXT-99: -------------------------------- FYI StringEscapeUtils.ESCAPE_JSON.translate(CharSequence, writer) appears to be slower because it calls `java.io.write(int c)`, which results in a large number of memory allocations before, which causes excessive GC load. Better to call `java.io.write(char cbuf[], int off, int len)` instead. > Performance Degradation for Escaping JSON > ----------------------------------------- > > Key: TEXT-99 > URL: https://issues.apache.org/jira/browse/TEXT-99 > Project: Commons Text > Issue Type: Bug > Affects Versions: 1.1 > Environment: OS X 10.11.6 > java version "1.8.0_60" > Java(TM) SE Runtime Environment (build 1.8.0_60-b27) > Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) > JProfiler 9.1 (Build 9128) > Reporter: Tom Howard > Priority: Minor > Labels: escape, json, performance > > There seams to be a small performance degradation on StringEscapeUtils.escapeJson(String) in commons-text v1.1 compared to commons-lang3 v3.5 > I have a performance test that involves (amongst other things) escaping 200,052 strings. Using commons-text v1.1 this consistently takes 100ms to 110ms. Using commons-lang3 v3.5 this consistently takes 92ms to 95ms. > Also, after escaping I'm writing it to using java.io.Writer.write(String). I would have assumed that StringEscapeUtils.ESCAPE_JSON.translate(CharSequence, writer) would yield better performance, however in the same test, using this method constantly takes approx 210ms and the parent method (which serialises the entire payload to JSON) takes approx 1750ms compared to approx 1400ms using StringEscapeUtils.escapeJson(String) from commons-lang3 v3.5 > I've marked the issue as minor, as it doesn't really impact me, but I thought I should share my findings. > The serialiser can be found at https://github.com/mountain-pass/ryvr/blob/master/src/main/java/au/com/mountainpass/ryvr/io/RyvrSerialiser.java and the performance test can be executed using `./gradlew testRyvrTests_Integration_Performance_Java_H2Local` > Also, I should mention that StringEscapeUtils.escapeJson is an order of magnitude faster than the equivalents from: > - org.json:json:20170516 > - org.unbescape:unbescape:1.1.5.RELEASE > - com.googlecode.json-simple:1.1.1 > - net.minidev:son-smart:2.3 > They literally take over 1000ms to do what StringEscapeUtils.escapeJson() does in about 100ms. If there are any other libs you would like me to test against for comparison purposes, please let me know. -- This message was sent by Atlassian JIRA (v6.4.14#64029)