{"id":1986,"date":"2023-09-04T19:18:32","date_gmt":"2023-09-04T13:48:32","guid":{"rendered":"https:\/\/judepereira.com\/blog\/?p=1986"},"modified":"2023-09-04T19:18:36","modified_gmt":"2023-09-04T13:48:36","slug":"kiss-hand-crafted-json-is-not-faster-than-objectmapper","status":"publish","type":"post","link":"https:\/\/judepereira.com\/blog\/kiss-hand-crafted-json-is-not-faster-than-objectmapper\/","title":{"rendered":"KISS: Hand crafted JSON is NOT faster than ObjectMapper"},"content":{"rendered":"\n<p>While going through some code earlier today, I encountered a method that attempted to escape quotes and back slashes in a poor way. The author of that method presumably thought that it\u2019d be way faster than Jackson\u2019s ObjectMapper.<\/p>\n\n\n\n<p>Here\u2019s what they wrote:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler\"><div class=\"wp-block-embed__wrapper\">\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist124537180\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-a-java\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-java  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"A.java content, created by judepereira on 01:30PM on September 04, 2023.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"A.java\">\n        <tr>\n          <td id=\"file-a-java-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-a-java-LC1\" class=\"blob-code blob-code-inner js-file-line\">public static String escapeString(Object o) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-a-java-LC2\" class=\"blob-code blob-code-inner js-file-line\">    if (o == null) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-a-java-LC3\" class=\"blob-code blob-code-inner js-file-line\">        return null;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-a-java-LC4\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-a-java-LC5\" class=\"blob-code blob-code-inner js-file-line\">    String str = o.toString();<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-a-java-LC6\" class=\"blob-code blob-code-inner js-file-line\">    if (str.contains(&quot;\\\\&quot;)) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-a-java-LC7\" class=\"blob-code blob-code-inner js-file-line\">        str = str.replace(&quot;\\\\&quot;, &quot;\\\\\\\\&quot;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-a-java-LC8\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-a-java-LC9\" class=\"blob-code blob-code-inner js-file-line\">    if (str.contains(&quot;\\&quot;&quot;)) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-a-java-LC10\" class=\"blob-code blob-code-inner js-file-line\">        str = str.replace(&quot;\\&quot;&quot;, &quot;\\\\\\&quot;&quot;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-a-java-LC11\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-a-java-LC12\" class=\"blob-code blob-code-inner js-file-line\">    return str;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-a-java-LC13\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/judepereira\/f9252d8505d9da3f6cb5963ea2f576e1\/raw\/badf78003964a5355bdbf3f7b286a99af959c062\/A.java\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/judepereira\/f9252d8505d9da3f6cb5963ea2f576e1#file-a-java\" class=\"Link--inTextBlock\">\n          A.java\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n<\/div><\/figure>\n\n\n\n<p>This produced illegal JSON strings, especially when the input string had new lines and carriage returns in it.<\/p>\n\n\n\n<p>Here\u2019s what I replaced it with:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler\"><div class=\"wp-block-embed__wrapper\">\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist124537225\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-a-java\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-java  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"A.java content, created by judepereira on 01:32PM on September 04, 2023.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"A.java\">\n        <tr>\n          <td id=\"file-a-java-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-a-java-LC1\" class=\"blob-code blob-code-inner js-file-line\">private static final ObjectMapper OM = new ObjectMapper();<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-a-java-LC2\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-a-java-LC3\" class=\"blob-code blob-code-inner js-file-line\">public static String escapeString(Object o) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-a-java-LC4\" class=\"blob-code blob-code-inner js-file-line\">    if (o == null) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-a-java-LC5\" class=\"blob-code blob-code-inner js-file-line\">        return null;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-a-java-LC6\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-a-java-LC7\" class=\"blob-code blob-code-inner js-file-line\">    try {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-a-java-LC8\" class=\"blob-code blob-code-inner js-file-line\">        \/\/ The string is automatically quoted. Therefore, return a new string that<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-a-java-LC9\" class=\"blob-code blob-code-inner js-file-line\">        \/\/ doesn&#39;t contain those quotes (since the caller appends quotes themselves).<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-a-java-LC10\" class=\"blob-code blob-code-inner js-file-line\">        val bytes = OM.writeValueAsBytes(o.toString());<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-a-java-LC11\" class=\"blob-code blob-code-inner js-file-line\">        return new String(bytes, 1, bytes.length &#8211; 2, StandardCharsets.UTF_8);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-a-java-LC12\" class=\"blob-code blob-code-inner js-file-line\">    } catch (JsonProcessingException e) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-a-java-LC13\" class=\"blob-code blob-code-inner js-file-line\">        return &quot;&quot;;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-a-java-LC14\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-a-java-LC15\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/judepereira\/b190ef1ecad3bcb6a79dd6e52878974a\/raw\/dbe9d1c80fc608949dfa62fc9a43a78bc1763da1\/A.java\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/judepereira\/b190ef1ecad3bcb6a79dd6e52878974a#file-a-java\" class=\"Link--inTextBlock\">\n          A.java\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n<\/div><\/figure>\n\n\n\n<p>At first, I was uncertain about the efficiency of either approaches. Let\u2019s JMH it:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler\"><div class=\"wp-block-embed__wrapper\">\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist124537233\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-a-java\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-java  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"A.java content, created by judepereira on 01:33PM on September 04, 2023.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"A.java\">\n        <tr>\n          <td id=\"file-a-java-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-a-java-LC1\" class=\"blob-code blob-code-inner js-file-line\">private static final ObjectMapper OM = new ObjectMapper();<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-a-java-LC2\" class=\"blob-code blob-code-inner js-file-line\">private static final String STR = &quot;hello world &#8211; the quick brown fox jumps over &quot; <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-a-java-LC3\" class=\"blob-code blob-code-inner js-file-line\">        + &quot;the lazy dog\\r\\n\\r\\nand here&#39;s &quot; <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-a-java-LC4\" class=\"blob-code blob-code-inner js-file-line\">        + &quot;a random slash\\\\, and some \\&quot;s&quot;;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-a-java-LC5\" class=\"blob-code blob-code-inner js-file-line\">        <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-a-java-LC6\" class=\"blob-code blob-code-inner js-file-line\">@Benchmark<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-a-java-LC7\" class=\"blob-code blob-code-inner js-file-line\">public void jsonStringSerialization(final Blackhole blackhole) throws Exception {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-a-java-LC8\" class=\"blob-code blob-code-inner js-file-line\">    byte[] obj = OM.writeValueAsBytes(STR);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-a-java-LC9\" class=\"blob-code blob-code-inner js-file-line\">    blackhole.consume(new String(obj, 1, obj.length &#8211; 2, StandardCharsets.UTF_8));<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-a-java-LC10\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-a-java-LC11\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-a-java-LC12\" class=\"blob-code blob-code-inner js-file-line\">@Benchmark<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-a-java-LC13\" class=\"blob-code blob-code-inner js-file-line\">public void jsonStringManual(final Blackhole blackhole) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-a-java-LC14\" class=\"blob-code blob-code-inner js-file-line\">    String str = STR;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-a-java-LC15\" class=\"blob-code blob-code-inner js-file-line\">    if (str.contains(&quot;\\\\&quot;)) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-a-java-LC16\" class=\"blob-code blob-code-inner js-file-line\">        str = str.replace(&quot;\\\\&quot;, &quot;\\\\\\\\&quot;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-a-java-LC17\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-a-java-LC18\" class=\"blob-code blob-code-inner js-file-line\">    if (str.contains(&quot;\\&quot;&quot;)) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-a-java-LC19\" class=\"blob-code blob-code-inner js-file-line\">        str = str.replace(&quot;\\&quot;&quot;, &quot;\\\\\\&quot;&quot;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-a-java-LC20\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-a-java-LC21\" class=\"blob-code blob-code-inner js-file-line\">    blackhole.consume(str);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-a-java-LC22\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/judepereira\/f67c2a8840a45440d39665e5160126f8\/raw\/038d280f1525327012de1a505c47b9d86bfb270d\/A.java\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/judepereira\/f67c2a8840a45440d39665e5160126f8#file-a-java\" class=\"Link--inTextBlock\">\n          A.java\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n<\/div><\/figure>\n\n\n\n<p>The results were quite astounding. I hadn\u2019t expected something like the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Benchmark                            Mode  Cnt        Score   Error  Units\nBenchmarks.jsonStringManual         thrpt    2    83301.447          ops\/s\nBenchmarks.jsonStringSerialization  thrpt    2  4171309.830          ops\/s<\/pre>\n\n\n\n<p>There must be something wrong, right? Perhaps it\u2019s because of the static string. Let\u2019s replace our static string with a random one generated for each iteration:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler\"><div class=\"wp-block-embed__wrapper\">\n<style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist124537256\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-a-java\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-java  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"A.java content, created by judepereira on 01:34PM on September 04, 2023.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"A.java\">\n        <tr>\n          <td id=\"file-a-java-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-a-java-LC1\" class=\"blob-code blob-code-inner js-file-line\">private static final ObjectMapper OM = new ObjectMapper();<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-a-java-LC2\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-a-java-LC3\" class=\"blob-code blob-code-inner js-file-line\">@Benchmark<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-a-java-LC4\" class=\"blob-code blob-code-inner js-file-line\">public void jsonStringSerialization(final Blackhole blackhole) throws Exception {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-a-java-LC5\" class=\"blob-code blob-code-inner js-file-line\">    byte[] obj = OM.writeValueAsBytes(randomString());<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-a-java-LC6\" class=\"blob-code blob-code-inner js-file-line\">    blackhole.consume(new String(obj, 1, obj.length &#8211; 2, StandardCharsets.UTF_8));<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-a-java-LC7\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-a-java-LC8\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-a-java-LC9\" class=\"blob-code blob-code-inner js-file-line\">@Benchmark<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-a-java-LC10\" class=\"blob-code blob-code-inner js-file-line\">public void jsonStringManual(final Blackhole blackhole) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-a-java-LC11\" class=\"blob-code blob-code-inner js-file-line\">    String str = randomString();<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-a-java-LC12\" class=\"blob-code blob-code-inner js-file-line\">    if (str.contains(&quot;\\\\&quot;)) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-a-java-LC13\" class=\"blob-code blob-code-inner js-file-line\">        str = str.replace(&quot;\\\\&quot;, &quot;\\\\\\\\&quot;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-a-java-LC14\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-a-java-LC15\" class=\"blob-code blob-code-inner js-file-line\">    if (str.contains(&quot;\\&quot;&quot;)) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-a-java-LC16\" class=\"blob-code blob-code-inner js-file-line\">        str = str.replace(&quot;\\&quot;&quot;, &quot;\\\\\\&quot;&quot;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-a-java-LC17\" class=\"blob-code blob-code-inner js-file-line\">    }<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-a-java-LC18\" class=\"blob-code blob-code-inner js-file-line\">    blackhole.consume(str);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-a-java-LC19\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-a-java-LC20\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-a-java-LC21\" class=\"blob-code blob-code-inner js-file-line\">private static String randomString() {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-a-java-LC22\" class=\"blob-code blob-code-inner js-file-line\">    return RandomStringUtils.random(75,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-a-java-LC23\" class=\"blob-code blob-code-inner js-file-line\">            &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;, &#39;g&#39;, &#39;h&#39;, &#39;i&#39;, &#39;j&#39;, &#39;k&#39;, &#39;l&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-a-java-LC24\" class=\"blob-code blob-code-inner js-file-line\">            &#39;m&#39;, &#39;n&#39;, &#39;o&#39;, &#39;p&#39;, &#39;q&#39;, &#39;r&#39;, &#39;s&#39;, &#39;t&#39;, &#39;u&#39;, &#39;v&#39;, &#39;w&#39;, &#39;x&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-a-java-LC25\" class=\"blob-code blob-code-inner js-file-line\">            &#39;y&#39;, &#39;z&#39;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-a-java-LC26\" class=\"blob-code blob-code-inner js-file-line\">            &#39;\\\\&#39;, &#39;\\r&#39;, &#39;\\n&#39;, &#39;\\&quot;&#39;, &#39;\\&#39;&#39;, &#39; &#39;);<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-a-java-LC27\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-a-java-LC28\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-a-java-LC29\" class=\"blob-code blob-code-inner js-file-line\">@Benchmark<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-a-java-LC30\" class=\"blob-code blob-code-inner js-file-line\">public void randomString(final Blackhole blackhole) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-a-java-LC31\" class=\"blob-code blob-code-inner js-file-line\">    blackhole.consume(randomString());<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-a-java-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-a-java-LC32\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/judepereira\/d6acc74263560ae06baebd1c475b8a14\/raw\/62cc2ff5ff3a8d74fae616ab480185524489569a\/A.java\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/judepereira\/d6acc74263560ae06baebd1c475b8a14#file-a-java\" class=\"Link--inTextBlock\">\n          A.java\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n\n<\/div><\/figure>\n\n\n\n<p>Here&#8217;s the JMH report:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Benchmark                            Mode  Cnt        Score   Error  Units\nBenchmarks.jsonStringManual         thrpt    2   133432.951          ops\/s\nBenchmarks.jsonStringSerialization  thrpt    2  1535802.541          ops\/s\nBenchmarks.randomString             thrpt    2  2871443.990          ops\/s<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"Conclusion\">Conclusion<\/h1>\n\n\n\n<p>KISS. Premature optimisations are harmful. Not only can they introduce bugs, but they could be slower than the industry standard. Benchmark everything carefully.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Premature optimisations are evil. Apart from being buggy, they might actually be slower than the industry standard.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[52],"tags":[696,697,463,694,698,26,693],"class_list":["post-1986","post","type-post","status-publish","format-standard","hentry","category-code","tag-benchmark","tag-jackson","tag-java","tag-jmh","tag-objectmapper","tag-performance","tag-premature-optimisations"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pqtyx-w2","jetpack-related-posts":[{"id":1918,"url":"https:\/\/judepereira.com\/blog\/sending-ota-updates-over-wifi-to-your-esp8266\/","url_meta":{"origin":1986,"position":0},"title":"Sending OTA updates over WiFi to your ESP8266","author":"Jude Pereira","date":"December 21, 2020","format":false,"excerpt":"This Christmas, I added a whole bunch of lights powered by 5V power sources. My goal was to switch them on at sunset, and switch them off on sunrise, by using a MOSFET for power control :) While I was doing this, I wanted to send OTA updates of my\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1936,"url":"https:\/\/judepereira.com\/blog\/taming-a-throttled-api-with-dynamic-proxies-in-java\/","url_meta":{"origin":1986,"position":1},"title":"Taming a throttled API with Dynamic Proxies in Java","author":"Jude Pereira","date":"January 20, 2021","format":false,"excerpt":"Recently, at CleverTap, we've begun migrating some of our largest clusters to a new protocol (for starters, think ~115 instances at a time). One of the most fun things I've had my hands on during this migration was the AWS Systems Manager API. When we scaled up our migrations gradually\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1675,"url":"https:\/\/judepereira.com\/blog\/sending-notifications-via-apples-new-http2-api-using-jetty-9-3-6\/","url_meta":{"origin":1986,"position":2},"title":"Sending notifications via Apple&#8217;s new HTTP\/2 API (using Jetty 9.3.6)","author":"Jude Pereira","date":"January 9, 2016","format":false,"excerpt":"HTTP\/2 is still very much new to Java, and as such, there are just two libraries who support it - Jetty (from 9.3), and Netty (in alpha). If you're going the Jetty way (as I have), you'll need to add their ALPN library to your boot classpath. Note: Jetty 9.3.x\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1845,"url":"https:\/\/judepereira.com\/blog\/intellij-on-steroids-with-g1-gc\/","url_meta":{"origin":1986,"position":3},"title":"IntelliJ on steroids with G1 GC","author":"Jude Pereira","date":"June 15, 2018","format":false,"excerpt":"Lately, I noticed that IntelliJ started to pause for quite some time during it's GC cycles, and that it was very frequent when I was editing three files (over 1.2k LOC each) split vertically. The current version of IntelliJ runs on a bundled version of Java 1.8, who's default garbage\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2139,"url":"https:\/\/judepereira.com\/blog\/when-to-delegate-work-to-a-virtual-engineer\/","url_meta":{"origin":1986,"position":4},"title":"When to Delegate Work to a Virtual Engineer","author":"Jude Pereira","date":"November 23, 2025","format":false,"excerpt":"With rapid advances in the field of engineering, when should you delegate work to a virtual engineer? Furthermore, what is a virtual engineer?","rel":"","context":"In &quot;Virtual Engineering&quot;","block_context":{"text":"Virtual Engineering","link":"https:\/\/judepereira.com\/blog\/category\/virtual-engineering\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/v2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/v2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/v2.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/v2.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/v2.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/v2.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1855,"url":"https:\/\/judepereira.com\/blog\/nginx-ingress-helm-k8s-rbac\/","url_meta":{"origin":1986,"position":5},"title":"Installing the Nginx Ingress Controller via Helm to a K8s cluster with RBAC enabled","author":"Jude Pereira","date":"October 1, 2018","format":false,"excerpt":"A lot of posts describe how to do this, but are fairly outdated, and do not mention the last supported K8s version. Here's a tried and tested way to do so via Helm. This has been tested on GKE, with the Kubernetes master version\u00a01.9.7-gke.6: Create the service account for Tiller\u2026","rel":"","context":"In &quot;another snippet | code&quot;","block_context":{"text":"another snippet | code","link":"https:\/\/judepereira.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/comments?post=1986"}],"version-history":[{"count":6,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1986\/revisions"}],"predecessor-version":[{"id":1992,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1986\/revisions\/1992"}],"wp:attachment":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/media?parent=1986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/categories?post=1986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/tags?post=1986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}