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

avoid more tuple allocations in Array constructors #18918

Merged
merged 1 commit into from
Oct 14, 2016

Conversation

JeffBezanson
Copy link
Sponsor Member

The problem here is that Array{...}((n,)) passes the tuple to C as Any, requiring it to be heap allocated. This is a quick fix that gets around that by unpacking the tuple from julia first.

Issues like this can potentially be eliminated once and for all by #12447. Another approach to explore is passing the tuple to C as Ptr{Int}, allowing it to remain stack allocated. @vtjnash Is that possible?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 14, 2016

You can ccall with the & syntax. Eventually Ref should also handle this, but not today.

@JeffBezanson
Copy link
Sponsor Member Author

I think I'll merge this for now since it's backportable, then later change the C entry points to never need tuples.

@JeffBezanson JeffBezanson merged commit 19e0f3d into master Oct 14, 2016
@tkelman tkelman deleted the jb/morearrayctors branch October 14, 2016 17:16
@andyferris
Copy link
Member

You can ccall with the & syntax. Eventually Ref should also handle this, but not today.

@vtjnash can I ask about this? I didn't realize there was a difference here. Can I pass any isbits type to ccall with & and it won't heap allocate it first? Or just Tuple?

And secondly, is this a pointer to the actual binding or does it make a stack copy? For interacting e.g. with BLAS I would love to be able to "initialize" an immutable in BLAS. However BLAS doesn't return a value, but wants a mutable pointer, and to make this fast, I would like that to be a pointer to my stack frame. I do realize attempting this violates semantics of immutability (to have C mutate an immutable), but possibly it is warranted as a kind of "constructor" for isbits types? (To make this semantically correct, if one could introduce a new uninitialized binding in the ccall that would be cool).

(I had tried this "hack" in the past but for local variables in a function it seemed to be making some kind of copy that you couldn't access after the ccall. I might have been using Ref instead of & since the docs specified & as old syntax, but I can't remember anymore).

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 15, 2016

This isn't the right forum to ask questions, please use the mailing list to avoid driving the issue OT. And no, you can't violate immutability, that's illogical.

@andyferris
Copy link
Member

Sorry Jameson (and everyone else). I got overexcited.... but the point is well taken.

tkelman pushed a commit that referenced this pull request Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants