[jose] Performance of Canonical JSON

Anders Rundgren <anders.rundgren.net@gmail.com> Fri, 07 December 2018 17:23 UTC

Return-Path: <anders.rundgren.net@gmail.com>
X-Original-To: jose@ietfa.amsl.com
Delivered-To: jose@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 77A08130ED8 for <jose@ietfa.amsl.com>; Fri, 7 Dec 2018 09:23:28 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lzbAuWMXizO6 for <jose@ietfa.amsl.com>; Fri, 7 Dec 2018 09:23:26 -0800 (PST)
Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 431A8130F0D for <jose@ietf.org>; Fri, 7 Dec 2018 09:23:26 -0800 (PST)
Received: by mail-wm1-x336.google.com with SMTP id q26so5236886wmf.5 for <jose@ietf.org>; Fri, 07 Dec 2018 09:23:26 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=A/G17PWUquGmU5KJSDXWX5bytqHn1YGcMKZXWxAy0U0=; b=dfHdAuSKTdtHbhfRSHDvB3uLFDEfT/HlYl22UkWpeDdfUAg1Alywp4/J+H8JjAIfhN r3y2yyyv8nZp0lBl/d8dQTIqa51A5SiawuSb4RP8uEbJgcpj7UiGRKYOdfcgYI3WBQpf PvV+HVpWAfXRQGu6Ff5jXrIGAiX0wD6GRKAdFdGOnPitWBgW74aRAPrgWaAvAlzr+dYp NHs8P8Cp0juimyHfxM8sAoPYAR+fv38QTPzJJfcLdFxvTbJNkVOSDlgnZyOHeLqF1A8y iorHWlxIDGfh3rxZobtfNas+5KTs9W8u5J2nZsJfBvEQFcKl7uyI8FwbGwiR1pYk71z8 zm4A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=A/G17PWUquGmU5KJSDXWX5bytqHn1YGcMKZXWxAy0U0=; b=twJhNETQjb+B/J0wQ+xuYThkd7dI7oUKumfhH3HuiicpmvgV43VcQ7+CasQzSCpJCk mwOq00ghQvgmhAv9JsxWGyFsa0+/kSEay1EZi1P7nN+od1pQl6CkK3izooJ0xJ14Eugz qjqvb+V0Ci2+EUae/bTWJFDr0QVjP0Hx37d3XSpk3u53NlZu7oALrqUrISGMNqaEOv6D 66PTUotz+6ebysnR50O0yiTGRKUXu1GIdTjVw54UumJ+ex0DzbSiNT7JoXOSZZLuEPvg sb0+92YR9VhY0mfS2MfaN0CQJPbha/boRA32vxRvbQzieRT8+e26Tps/ilSsnpqFHjGf I98g==
X-Gm-Message-State: AA+aEWZowvkwEoTlez4JOIZ/GJWtYU+6fQ6mJeM773k+2sreTp6ZPPGa 5tNg2qTuJnENWUv0vPWkuGenDnqk
X-Google-Smtp-Source: AFSGD/WPnwOCmqKARtDCl9t2K8B8Z/IuOWrM+JIMvqmmUWoqVLcICZbTLdR9HpN6bO9zSsLsNL/VDQ==
X-Received: by 2002:a1c:1112:: with SMTP id 18mr3226143wmr.30.1544203404227; Fri, 07 Dec 2018 09:23:24 -0800 (PST)
Received: from [192.168.1.79] (25.131.146.77.rev.sfr.net. [77.146.131.25]) by smtp.googlemail.com with ESMTPSA id k7sm5360014wrl.51.2018.12.07.09.23.22 for <jose@ietf.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 09:23:23 -0800 (PST)
To: "jose@ietf.org" <jose@ietf.org>
From: Anders Rundgren <anders.rundgren.net@gmail.com>
Message-ID: <3466a48c-115d-3810-4c94-0e213ba407fd@gmail.com>
Date: Fri, 07 Dec 2018 18:23:21 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"; format="flowed"
Content-Transfer-Encoding: 8bit
Content-Language: en-US
Archived-At: <https://mailarchive.ietf.org/arch/msg/jose/xI61V2n3wdHtrIqGpUxekGEFd5w>
Subject: [jose] Performance of Canonical JSON
X-BeenThere: jose@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Javascript Object Signing and Encryption <jose.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/jose>, <mailto:jose-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/jose/>
List-Post: <mailto:jose@ietf.org>
List-Help: <mailto:jose-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/jose>, <mailto:jose-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 07 Dec 2018 17:23:28 -0000

Since XML Canonicalization has a reputation of not only being brittle but also terribly slow, I tested JCS [1] with the following JSON file:
{
   "1": {"f": {"f": "hi","F": 5} ,"\n": 56.0},
   "10": { },
   "": "empty",
   "a": { },
   "111": [ {"e": "yes","E": "no" } ],
   "A": { }
}

Expected output: {"":"empty","1":{"\n":56,"f":{"F":5,"f":"hi"}},"10":{},"111":[{"E":"no","e":"yes"}],"A":{},"a":{}}

Since JCS only is a serialization concept (parsing is unaffected), I compared the execution speed of standard serialization versus canonicalized serialization.

Using https://www.npmjs.com/package/canonicalize the performance penalty was about 2.4 compared to JSON.stringify().
Using my homegrown JSON tools written in Java having an integrated "canonicalize" serializer option the performance penalty was about 1.4

Anders

1] https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-01