Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Faster closure variable capture

License

NotificationsYou must be signed in to change notification settings

c42f/FastClosures.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

A workaround forJuliaLang/julia#15276, for julia-1.x,somewhat in the spirit of FastAnonymous.jl. Provides the@closure macro,which wraps a closure in alet block to make reading variable bindings privateto the closure. In certain cases, this make using the closure - and the codesurrouding it - much faster. Note that it's not clear that thelet blocktrick implemented in this package helps at all in julia-0.5. However, julia-0.5compatibility is provided for backward compatibility convenience.

Interface

@closure closure_expression

Wrap the closure definitionclosure_expression in a let block to encouragethe julia compiler to generate improved type information. For example:

callfunc(f)=f()functionfoo(n)for i=1:nif i>= n# Unlikely event - should be fast.  However, capture of `i` inside# the closure confuses the julia-0.6 compiler and causes it to box# the variable `i`, leading to a 100x performance hit if you remove# the `@closure`.callfunc(@closure ()->println("Hello\$i"))endendend

Here's a further example of where this helps:

using FastClosures# code_warntype problemfunctionf1()iftrueend    r=1    cb= ()->ridentity(cb)end# code_warntype cleanfunctionf2()iftrueend    r=1    cb=@closure ()->ridentity(cb)end@code_warntypef1()@code_warntypef2()

About

Faster closure variable capture

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp