groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From C├ędric Champeau <cedric.champ...@gmail.com>
Subject Re: groovy git commit: Refine DgmConverter to gain better IO performance
Date Tue, 12 Dec 2017 14:40:31 GMT
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 <sunlan@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 <sunlan@apache.org>
> Authored: Tue Dec 12 19:54:35 2017 +0800
> Committer: sunlan <sunlan@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");
>
>

Mime
View raw message