summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2023-01-17 16:21:13 -0500
committerGitHub <noreply@github.com>2023-01-17 16:21:13 -0500
commita9bcc058bb4cd954e8406c93debb876983627ca9 (patch)
tree9982c24fbedd2fd34a2c6cf59e1159e40c62c210 /doc
parentdf6b72b8ff7af16a56fa48f3b4abb1d8850f4d1c (diff)
Update yjit.md
Diffstat (limited to 'doc')
-rw-r--r--doc/yjit/yjit.md7
1 files changed, 4 insertions, 3 deletions
diff --git a/doc/yjit/yjit.md b/doc/yjit/yjit.md
index f68b36b65b..01dd77410b 100644
--- a/doc/yjit/yjit.md
+++ b/doc/yjit/yjit.md
@@ -172,18 +172,19 @@ We have collected a set of benchmarks and implemented a simple benchmarking harn
### Performance Tips
-This section contains tips on writing Ruby code that will run as fast as possible on YJIT. Some of this advice is based on current limitations of YJIT, while other advice is broadly applicable. It probably won't be practical to apply these tips everywhere in your codebase, but you can profile your code using a tool such as [stackprof](https://github.com/tmm1/stackprof) and refactor the specific methods that make up the largest fractions of the execution time.
+This section contains tips on writing Ruby code that will run as fast as possible on YJIT. Some of this advice is based on current limitations of YJIT, while other advice is broadly applicable. It probably won't be practical to apply these tips everywhere in your codebase. You should ideally start by profiling your application using a tool such as [stackprof](https://github.com/tmm1/stackprof) so that you can determine which methods make up most of the execution time. You can then refactor the specific methods that make up the largest fractions of the execution time. We do not recommend modifying your entire codebase based on the current limitations of YJIT.
- Use exceptions for error recovery only, not as part of normal control-flow
- Avoid redefining basic integer operations (i.e. +, -, <, >, etc.)
- Avoid redefining the meaning of `nil`, equality, etc.
- Avoid allocating objects in the hot parts of your code
-- Use while loops if you can, instead of `integer.times`
- Minimize layers of indirection
- Avoid classes that wrap objects if you can
- Avoid methods that just call another method, trivial one liner methods
-- CRuby method calls are costly. Favor larger methods over smaller methods.
- Try to write code so that the same variables always have the same type
+- Use while loops if you can, instead of `integer.times`
+ - This is not idiomatic Ruby, but could help in hot methods
+- CRuby method calls are costly. Avoid things such as methods that only return a value from a hash or return a constant.
You can also use the `--yjit-stats` command-line option to see which bytecodes cause YJIT to exit, and refactor your code to avoid using these instructions in the hottest methods of your code.