You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Cédric Champeau <ce...@gmail.com> on 2017/12/12 14:40:31 UTC

Re: groovy git commit: Refine DgmConverter to gain better IO performance

Why is that more performant ? Using a buffered writer is actually slower
when you know the bytes to write. I don't think it's an improvement. We had
removed buffering in the past for that same reason.

2017-12-12 12:54 GMT+01:00 <su...@apache.org>:

> Repository: groovy
> Updated Branches:
>   refs/heads/master dc30ad7d1 -> 1b248d367
>
>
> Refine DgmConverter to gain better IO performance
>
>
> Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
> Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1b248d36
> Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1b248d36
> Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1b248d36
>
> Branch: refs/heads/master
> Commit: 1b248d367d7e931becdcc47eaffc9073b2851ac2
> Parents: dc30ad7
> Author: sunlan <su...@apache.org>
> Authored: Tue Dec 12 19:54:35 2017 +0800
> Committer: sunlan <su...@apache.org>
> Committed: Tue Dec 12 19:54:35 2017 +0800
>
> ----------------------------------------------------------------------
>  .../org/codehaus/groovy/tools/DgmConverter.java | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/groovy/blob/1b248d36/src/main/org/
> codehaus/groovy/tools/DgmConverter.java
> ----------------------------------------------------------------------
> diff --git a/src/main/org/codehaus/groovy/tools/DgmConverter.java
> b/src/main/org/codehaus/groovy/tools/DgmConverter.java
> index ba714bb..5228a93 100644
> --- a/src/main/org/codehaus/groovy/tools/DgmConverter.java
> +++ b/src/main/org/codehaus/groovy/tools/DgmConverter.java
> @@ -29,6 +29,7 @@ import org.objectweb.asm.Label;
>  import org.objectweb.asm.MethodVisitor;
>  import org.objectweb.asm.Opcodes;
>
> +import java.io.BufferedOutputStream;
>  import java.io.File;
>  import java.io.FileOutputStream;
>  import java.io.IOException;
> @@ -93,12 +94,23 @@ public class DgmConverter implements Opcodes {
>              cw.visitEnd();
>
>              final byte[] bytes = cw.toByteArray();
> +
>              File targetFile = new File(targetDirectory + className +
> ".class").getCanonicalFile();
>              targetFile.getParentFile().mkdirs();
> -            final FileOutputStream fileOutputStream = new
> FileOutputStream(targetFile);
> -            fileOutputStream.write(bytes);
> -            fileOutputStream.flush();
> -            fileOutputStream.close();
> +
> +            BufferedOutputStream bufferedOutputStream = null;
> +            try {
> +                bufferedOutputStream =
> +                        new BufferedOutputStream(
> +                                new FileOutputStream(targetFile));
> +
> +                bufferedOutputStream.write(bytes);
> +                bufferedOutputStream.flush();
> +            } finally {
> +                if (null != bufferedOutputStream) {
> +                    bufferedOutputStream.close();
> +                }
> +            }
>          }
>
>          GeneratedMetaMethod.DgmMethodRecord.saveDgmInfo(records,
> targetDirectory+"/META-INF/dgminfo");
>
>

Re: groovy git commit: Refine DgmConverter to gain better IO performance

Posted by "Daniel.Sun" <su...@apache.org>.
Gotcha.
I'll revert it ;)

Cheers,
Daniel.Sun



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: groovy git commit: Refine DgmConverter to gain better IO performance

Posted by Cédric Champeau <ce...@gmail.com>.
Buffered writing only makes sense if the writes are smaller than the buffer
size, and that you do multiple writes. This is not the case here, so
buffered won't help.

2017-12-12 16:34 GMT+01:00 Daniel.Sun <su...@apache.org>:

> Hi  Cédric,
>
>       > Using a buffered writer is actually slower when you know the bytes
> to write.
>       To be frank, it's hard for me to believe... because
> BufferedOutputStream will keep the bytes to output util the buffer is full,
> so it can reduce the times to access the disk(As we all know, accessing
> disk
> is much slower than accessing memory).
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>

Re: groovy git commit: Refine DgmConverter to gain better IO performance

Posted by "Daniel.Sun" <su...@apache.org>.
Hi  Cédric,

      > Using a buffered writer is actually slower when you know the bytes
to write.
      To be frank, it's hard for me to believe... because
BufferedOutputStream will keep the bytes to output util the buffer is full,
so it can reduce the times to access the disk(As we all know, accessing disk
is much slower than accessing memory).

Cheers,
Daniel.Sun



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html