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

faster active patterns by allowing hints for type guessing #111

Closed
thautwarm opened this issue Mar 13, 2021 · 1 comment
Closed

faster active patterns by allowing hints for type guessing #111

thautwarm opened this issue Mar 13, 2021 · 1 comment

Comments

@thautwarm
Copy link
Owner

Before:

julia> @active GlobalRef(x) begin
           if x isa GlobalRef
               (x.mod, x.name)
           else
               nothing
           end
       end

After:

julia> @active GlobalRef(x)::GlobalRef begin
           if x isa GlobalRef
               (x.mod, x.name)
           else
               nothing
           end
       end
thautwarm added a commit that referenced this issue Mar 13, 2021
@thautwarm
Copy link
Owner Author

 xs = [ GlobalRef(Main, :x), :(a.b), :+, GlobalRef(MLStyle, Symbol("@", :match)) ]

julia>  f(x) = @match x begin
                  GlobalRef(_, x) => x
                  :($_.$x) => x
                  _ => nothing
              end

julia> @btime [f(x) for x in xs]

before:

julia> @btime [f(x) for x in xs]
  442.929 ns (5 allocations: 272 bytes)
4-element Vector{Union{Nothing, Symbol}}:
 :x
 :b
 nothing
 Symbol("@match")

after

julia> @btime [f(x) for x in xs]
  408.000 ns (5 allocations: 272 bytes)
4-element Vector{Union{Nothing, Symbol}}:
 :x
 :b
 nothing
 Symbol("@match")

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

No branches or pull requests

1 participant