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

Improve efficiency and speed of the macro expansion #8

Merged
merged 10 commits into from
Nov 10, 2022
Merged

Conversation

jmert
Copy link
Owner

@jmert jmert commented Nov 10, 2022

This PR contains a number of code and performance improvements. (Commit f815fc1 by far dominates in the performance improvement.) In all, the time to generate bit flag definitions for a large-ish test case is reduced by about 35%.

The benchmarking script was generated with the code:

open("perf_many_bitflags.jl", "w") do fh                                                                                                                                                                                                      
    write(fh, "using BitFlags\n\n")                                                                                                                                                                                                           
                                                                                                                                                                                                                                              
    for ii in 1:16                                                                                                                                                                                                                            
        write(fh, "@bitflag InlineFlags$(ii)$(ii > 8 ? "::UInt64" : "")")                                                                                                                                                                     
        for jj in 1:3ii                                                                                                                                                                                                                       
            write(fh, " inlineflag$(ii)_$(jj)")                                                                                                                                                                                               
        end                                                                                                                                                                                                                                   
        write(fh, "\n\n")                                                                                                                                                                                                                     
    end                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                              
    for ii in 1:16                                                                                                                                                                                                                            
        write(fh, "@bitflag InlineFlags$(ii)", ii > 8 ? "::UInt64" : "", " begin\n")                                                                                                                                                          
        for jj in 1:3ii                                                                                                                                                                                                                       
            write(fh, "    blockflag$(ii)_$(jj)",                                                                                                                                                                                             
                      ii % 2 == 0 && jj == 1 ? " = Int8(0)" : "", "\n")                                                                                                                                                                       
        end                                                                                                                                                                                                                                   
        write(fh, "end\n\n")                                                                                                                                                                                                                  
    end                                                                                                                                                                                                                                       
end

Benchmarking an include into an empty module on multiple version of Julia (keeping just the minimum) produced the following graph. (0.1.5 is the base release before the first commit, and 0.1.5-9-* is the last commit in the PR.)

faster_codegen

jmert added 9 commits November 9, 2022 17:24
The goal is to improve type inference of values dependent on the
dynamically-generated `basetype` data type.
The value->name mapping is still emitted to a function definition,
but it's actually easier to internally just use parallel vectors of
names and value separately.

At the same time, generate all three of:
- the `namemap` vector of tuples
- the `instances` expressions
- the `const $flag` expressions
within a common loop that iterates through the names and values only
once.
@codecov
Copy link

codecov bot commented Nov 10, 2022

Codecov Report

Merging #8 (be9a9eb) into master (3191eee) will increase coverage by 2.26%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master       #8      +/-   ##
==========================================
+ Coverage   97.08%   99.34%   +2.26%     
==========================================
  Files           1        1              
  Lines         137      153      +16     
==========================================
+ Hits          133      152      +19     
+ Misses          4        1       -3     
Impacted Files Coverage Δ
src/BitFlags.jl 99.34% <100.00%> (+2.26%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jmert jmert merged commit 74d13e3 into master Nov 10, 2022
@jmert jmert deleted the faster_codegen branch November 10, 2022 15:25
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.

1 participant