Skip to content

Commit fcc21b3

Browse files
committed
docs: Explain static dispatch advantage more clearly
1 parent 522d09d commit fcc21b3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/doc/trpl/static-and-dynamic-dispatch.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ fn main() {
7979
}
8080
```
8181

82-
This has some upsides: static dispatching of any method calls, allowing for
83-
inlining and hence usually higher performance. It also has some downsides:
84-
causing code bloat due to many copies of the same function existing in the
85-
binary, one for each type.
82+
This has a great upside: static dispatch allows function calls to be
83+
inlined because the callee is known at compile time, and inlining is
84+
the key to good optimization. Static dispatch is fast, but it comes at
85+
a tradeoff: 'code bloat', due to many copies of the same function
86+
existing in the binary, one for each type.
8687

8788
Furthermore, compilers aren’t perfect and may “optimise” code to become slower.
8889
For example, functions inlined too eagerly will bloat the instruction cache

0 commit comments

Comments
 (0)