Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getfield instead of getproperty for performance #142

Merged
merged 1 commit into from
May 12, 2020

Conversation

bicycle1885
Copy link
Member

This fixes #139.

For some unknown reason, Julia seems to fail to inline getproperty of StreamReader, which causes significant performance degradation as reported in #139.

This change works around the problem by directly calling getfield(reader, :ptr) in some performance-critical functions. The performance improvement was ~20% in uniprot_sprot.xml.gz downloaded from https://www.uniprot.org/downloads.

using EzXML
using Printf

function scan(filepath)
    s = time()
    n = 0
    open(EzXML.StreamReader, filepath) do reader
        for node in reader
            n += 1
            if n % (1 << 20) == 0
                t = time() - s
                @printf "%10d nodes - %.1fk nodes/sec\n" n (n / t / 1000)
                if t > 5
                    break
                end
            end
        end
    end
    return n
end

for _ in 1:3
    scan("uniprot_sprot.xml.gz")
end

Before:

   1048576 nodes - 1542.3k nodes/sec
   2097152 nodes - 1588.9k nodes/sec
   3145728 nodes - 1620.1k nodes/sec
   4194304 nodes - 1659.2k nodes/sec
   5242880 nodes - 1705.0k nodes/sec
   6291456 nodes - 1739.3k nodes/sec
   7340032 nodes - 1768.2k nodes/sec
   8388608 nodes - 1786.7k nodes/sec
   9437184 nodes - 1800.8k nodes/sec
   1048576 nodes - 1941.0k nodes/sec
   2097152 nodes - 1935.6k nodes/sec
   3145728 nodes - 1932.0k nodes/sec
   4194304 nodes - 1928.1k nodes/sec
   5242880 nodes - 1928.4k nodes/sec
   6291456 nodes - 1929.7k nodes/sec
   7340032 nodes - 1936.2k nodes/sec
   8388608 nodes - 1938.6k nodes/sec
   9437184 nodes - 1937.2k nodes/sec
  10485760 nodes - 1939.2k nodes/sec
   1048576 nodes - 1950.4k nodes/sec
   2097152 nodes - 1947.5k nodes/sec
   3145728 nodes - 1935.5k nodes/sec
   4194304 nodes - 1930.1k nodes/sec
   5242880 nodes - 1928.0k nodes/sec
   6291456 nodes - 1928.6k nodes/sec
   7340032 nodes - 1934.5k nodes/sec
   8388608 nodes - 1934.9k nodes/sec
   9437184 nodes - 1934.0k nodes/sec
  10485760 nodes - 1935.9k nodes/sec

After:

   1048576 nodes - 2111.7k nodes/sec
   2097152 nodes - 2077.4k nodes/sec
   3145728 nodes - 2176.8k nodes/sec
   4194304 nodes - 2243.5k nodes/sec
   5242880 nodes - 2280.7k nodes/sec
   6291456 nodes - 2309.4k nodes/sec
   7340032 nodes - 2319.1k nodes/sec
   8388608 nodes - 2339.3k nodes/sec
   9437184 nodes - 2352.7k nodes/sec
  10485760 nodes - 2366.4k nodes/sec
  11534336 nodes - 2375.7k nodes/sec
  12582912 nodes - 2381.3k nodes/sec
   1048576 nodes - 2459.0k nodes/sec
   2097152 nodes - 2470.2k nodes/sec
   3145728 nodes - 2468.4k nodes/sec
   4194304 nodes - 2466.8k nodes/sec
   5242880 nodes - 2465.2k nodes/sec
   6291456 nodes - 2465.9k nodes/sec
   7340032 nodes - 2474.2k nodes/sec
   8388608 nodes - 2477.2k nodes/sec
   9437184 nodes - 2467.1k nodes/sec
  10485760 nodes - 2470.8k nodes/sec
  11534336 nodes - 2471.1k nodes/sec
  12582912 nodes - 2470.6k nodes/sec
   1048576 nodes - 2488.9k nodes/sec
   2097152 nodes - 2481.8k nodes/sec
   3145728 nodes - 2472.1k nodes/sec
   4194304 nodes - 2468.2k nodes/sec
   5242880 nodes - 2462.9k nodes/sec
   6291456 nodes - 2466.1k nodes/sec
   7340032 nodes - 2472.9k nodes/sec
   8388608 nodes - 2475.4k nodes/sec
   9437184 nodes - 2474.2k nodes/sec
  10485760 nodes - 2474.1k nodes/sec
  11534336 nodes - 2472.8k nodes/sec
  12582912 nodes - 2470.5k nodes/sec

Versioninfo:

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 5 2400G with Radeon Vega Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, znver1)
Environment:
  JULIA_PROJECT = @.

@codecov
Copy link

codecov bot commented May 12, 2020

Codecov Report

Merging #142 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #142   +/-   ##
=======================================
  Coverage   93.55%   93.55%           
=======================================
  Files           7        7           
  Lines         760      760           
=======================================
  Hits          711      711           
  Misses         49       49           
Impacted Files Coverage Δ
src/streamreader.jl 89.93% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 830d3c2...904ef69. Read the comment docs.

@bicycle1885 bicycle1885 merged commit 4a4891c into master May 12, 2020
@bicycle1885 bicycle1885 deleted the streamreader-performance branch May 12, 2020 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance implications of getproperty
1 participant