# Performance drawback with subtyping

**URL:** https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939
**Category:** Performance
**Created:** [December 16, 2020, 4:02pm UTC](https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939 "2020-12-16T16:02:42Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [December 16, 2020, 8:50pm UTC](https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939/9 "2020-12-16T20:50:14Z")

</div>

Try writing `paint2` like this:

```julia
function paint2(p::Picture)
  s = 0.
  for l in p.lines
    if l isa LineA
      s += paint(l::LineA)
    else
      s += paint(l::LineB)
    end
  end
  s
end

```

Does that improve performance?

---

_[View the full topic](https://discourse.julialang.org/t/performance-drawback-with-subtyping/51939)._
