[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-nio-dev
Subject:    Re: 8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char
From:       Brian Burkhalter <brian.burkhalter () oracle ! com>
Date:       2019-02-22 15:34:53
Message-ID: C65DA27B-5311-4141-86D6-8DAF9E97C177 () oracle ! com
[Download RAW message or body]

> On Feb 22, 2019, at 7:18 AM, Brian Burkhalter <brian.burkhalter@oracle.com> wrote:
> 
> > > http://cr.openjdk.java.net/~bpb/8011135/webrev/ \
> > > <http://cr.openjdk.java.net/~bpb/8011135/webrev/>This version looks good.
> > 
> > Claes might have some comments on the microbenchmark, my only comment that future \
> > maintainers might wonder about the +42 and also why the position is reset to 21 \
> > (I assume it would be buf.clear(); buf.put(str);
> 
> No good reason really. The 21 and 42 can be removed if we like.

I updated the benchmark as below and re-ran it to verify. I'll push this version \
unless I see an objection.

Thanks,

Brian

--- a/test/micro/org/openjdk/bench/java/nio/CharBuffers.java
+++ b/test/micro/org/openjdk/bench/java/nio/CharBuffers.java
@@ -54,13 +54,12 @@
         char[] c = new char[numChars];
         Arrays.fill(c, 'X');
         str = String.valueOf(c);
-        buf = CharBuffer.allocate(numChars + 42);
+        buf = CharBuffer.allocate(numChars);
     }
 
     @Benchmark
     public CharBuffer putString() {
-        buf.rewind();
-        buf.position(21);
+        buf.clear();
         return buf.put(str);
     }


[Attachment #3 (unknown)]

<html><head><meta http-equiv="Content-Type" content="text/html; \
charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" \
class=""><div class="">On Feb 22, 2019, at 7:18 AM, Brian Burkhalter &lt;<a \
href="mailto:brian.burkhalter@oracle.com" \
class="">brian.burkhalter@oracle.com</a>&gt; wrote:</div><br \
class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: \
break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div \
class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: \
12px; font-style: normal; font-variant-caps: normal; font-weight: normal; \
letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; \
text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; \
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: \
none;"><div class=""><blockquote type="cite" \
cite="mid:12EDE4D8-868A-4E67-8FC4-819D092D9045@oracle.com" class="" \
style="font-family: Helvetica; font-size: 12px; font-style: normal; \
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: \
start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: \
0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); \
text-decoration: none;"><div class=""><a \
href="http://cr.openjdk.java.net/~bpb/8011135/webrev/" class="" \
moz-do-not-send="true">http://cr.openjdk.java.net/~bpb/8011135/webrev/</a></div></blockquote><span \
class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; \
font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: \
normal; text-align: start; text-indent: 0px; text-transform: none; white-space: \
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, \
255, 255); text-decoration: none; float: none; display: inline !important;">This \
version looks good.</span><br class="" style="caret-color: rgb(0, 0, 0); font-family: \
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; \
font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; \
text-transform: none; white-space: normal; word-spacing: 0px; \
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); \
text-decoration: none;"><br class="" style="caret-color: rgb(0, 0, 0); font-family: \
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; \
font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; \
text-transform: none; white-space: normal; word-spacing: 0px; \
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); \
text-decoration: none;"><span class="" style="caret-color: rgb(0, 0, 0); font-family: \
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; \
font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; \
text-transform: none; white-space: normal; word-spacing: 0px; \
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); \
text-decoration: none; float: none; display: inline !important;">Claes might have \
some comments on the microbenchmark, my only comment that future maintainers might \
wonder about the +42 and also why the position is reset to 21 (I assume it would be \
buf.clear(); buf.put(str);</span></div></blockquote></div><br class=""><div \
class="">No good reason really. The 21 and 42 can be removed if we \
like.</div></div></div></blockquote></div><br class=""><div class="">I updated the \
benchmark as below and re-ran it to verify. I'll push this version unless I see an \
objection.</div><div class=""><br class=""></div><div class="">Thanks,</div><div \
class=""><br class=""></div><div class="">Brian</div><div class=""><br \
class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; \
font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgba(255, \
255, 255, 0.811765);" class=""><span style="font-variant-ligatures: \
no-common-ligatures" class="">--- \
a/test/micro/org/openjdk/bench/java/nio/CharBuffers.java</span></div><div \
style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; \
font-family: Menlo; background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">+++ \
b/test/micro/org/openjdk/bench/java/nio/CharBuffers.java</span></div><div \
style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; \
font-family: Menlo; background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">@@ -54,13 +54,12 \
@@</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; \
line-height: normal; font-family: Menlo; background-color: rgba(255, 255, 255, \
0.811765);" class=""><span style="font-variant-ligatures: no-common-ligatures" \
class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; char[] c = new \
char[numChars];</span></div><div style="margin: 0px; font-stretch: normal; font-size: \
11px; line-height: normal; font-family: Menlo; background-color: rgba(255, 255, 255, \
0.811765);" class=""><span style="font-variant-ligatures: no-common-ligatures" \
class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Arrays.fill(c, 'X');</span></div><div \
style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; \
font-family: Menlo; background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; \
&nbsp; &nbsp; str = String.valueOf(c);</span></div><div style="margin: 0px; \
font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; \
background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">-&nbsp; &nbsp; &nbsp; \
&nbsp; buf = CharBuffer.allocate(numChars + 42);</span></div><div style="margin: 0px; \
font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; \
background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">+&nbsp; &nbsp; &nbsp; \
&nbsp; buf = CharBuffer.allocate(numChars);</span></div><div style="margin: 0px; \
font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; \
background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; \
}</span></div><p style="margin: 0px; font-stretch: normal; font-size: 11px; \
line-height: normal; font-family: Menlo; background-color: rgba(255, 255, 255, \
0.811765); min-height: 13px;" class=""><span style="font-variant-ligatures: \
no-common-ligatures" class="">&nbsp;</span><br \
class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; \
font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgba(255, \
255, 255, 0.811765);" class=""><span style="font-variant-ligatures: \
no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; @Benchmark</span></div><div \
style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; \
font-family: Menlo; background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; \
public CharBuffer putString() {</span></div><div style="margin: 0px; font-stretch: \
normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: \
rgba(255, 255, 255, 0.811765);" class=""><span style="font-variant-ligatures: \
no-common-ligatures" class="">-&nbsp; &nbsp; &nbsp; &nbsp; \
buf.rewind();</span></div><div style="margin: 0px; font-stretch: normal; font-size: \
11px; line-height: normal; font-family: Menlo; background-color: rgba(255, 255, 255, \
0.811765);" class=""><span style="font-variant-ligatures: no-common-ligatures" \
class="">-&nbsp; &nbsp; &nbsp; &nbsp; buf.position(21);</span></div><div \
style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; \
font-family: Menlo; background-color: rgba(255, 255, 255, 0.811765);" class=""><span \
style="font-variant-ligatures: no-common-ligatures" class="">+&nbsp; &nbsp; &nbsp; \
&nbsp; buf.clear();</span></div><div style="margin: 0px; font-stretch: normal; \
font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgba(255, \
255, 255, 0.811765);" class=""><span style="font-variant-ligatures: \
no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; return \
buf.put(str);</span></div><div style="margin: 0px; font-stretch: normal; font-size: \
11px; line-height: normal; font-family: Menlo; background-color: rgba(255, 255, 255, \
0.811765);" class=""><span style="font-variant-ligatures: no-common-ligatures" \
class="">&nbsp;&nbsp; &nbsp; }</span></div></div><div class=""><span \
style="font-variant-ligatures: no-common-ligatures" class=""><br \
class=""></span></div></body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic