# When to use broadcasting with . vs map

**URL:** <https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078>\
**Category:** General Usage\
**Tags:** broadcast\
**Created:** [March 27, 2021, 2:05pm UTC](https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078 "2021-03-27T14:05:43Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 3, 2022, 5:42am UTC](https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078/21 "2022-10-03T05:42:08Z")

</div>

That’s because `broadcast` is special cased for tuples to call map: `@inline broadcast(f, t::NTuple{N,Any}, ts::Vararg{NTuple{N,Any}}) where {N} = map(f, t, ts...)`. In the general case, it really is just `broadcast(f::Tf, As...) where {Tf} = materialize(broadcasted(f, As...))`, which I suppose dot syntax always lowers to.

I don’t think the accepted comment about `collect` being the source of worse performance would apply to tuples, it appears that `collect` occurs in the fallback `broadcastable(x) = collect(x)`, but tuples are one of the many types where `broadcastable` returns the input. Not sure exactly where in the broadcast machinery is the source of worse performance than `map`.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [October 3, 2022, 11:10am UTC](https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078/22 "2022-10-03T11:10:33Z")

</div>

Ahh right was wondering why that example wasn’t as bad as I thought. It’s a little confusing that `.` and `broadcast` are not actually the same.

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [October 3, 2022, 9:42pm UTC](https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078/23 "2022-10-03T21:42:40Z")

</div>

It seems like having \>3 distinct types in the tuple triggers some heuristic and demotes the return type to `NTuple{N, Any}`.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 4, 2022, 2:49am UTC](https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078/24 "2022-10-04T02:49:56Z")

</div>

Sounds similar to the [Union-splitting](https://julialang.org/blog/2018/08/union-splitting/) limit, but I’m not sure because inferring up to 3-4 types in a Union is not at all the same as inferring a tuple of 3-4 types in any number or order, that’s way more than 3-4 tuple types.

[Previous page](https://discourse.julialang.org/t/when-to-use-broadcasting-with-vs-map/58078.md?page=1)
