summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2024-04-03 17:28:01 -0400
committerGitHub <noreply@github.com>2024-04-03 21:28:01 +0000
commit571bfc7402bb05becb00a7ea1b8971ac6ad92d8a (patch)
tree728e8031fab16ceb1f00dcc71af202ae373ccb37 /doc
parentc7cda1ae9ba39466f8c14820d9ffc626503c82eb (diff)
YJIT: update code optimization tips in yjit.md (#10445)
* YJIT: update code optimization tips in yjit.md * Function => method
Diffstat (limited to 'doc')
-rw-r--r--doc/yjit/yjit.md10
1 files changed, 6 insertions, 4 deletions
diff --git a/doc/yjit/yjit.md b/doc/yjit/yjit.md
index 4508bce25f..8ea3409e48 100644
--- a/doc/yjit/yjit.md
+++ b/doc/yjit/yjit.md
@@ -265,10 +265,12 @@ This section contains tips on writing Ruby code that will run as fast as possibl
- Avoid redefining the meaning of `nil`, equality, etc.
- Avoid allocating objects in the hot parts of your code
- Minimize layers of indirection
- - Avoid classes that wrap objects if you can
- - Avoid methods that just call another method, trivial one-liner methods
-- Try to write code so that the same variables always have the same type
-- CRuby method calls are costly. Avoid things such as methods that only return a value from a hash or return a constant.
+ - Avoid writing wrapper classes if you can (e.g. a class that only wraps a Ruby hash)
+ - Avoid methods that just call another method
+- Ruby method calls are costly. Avoid things such as methods that only return a value from a hash
+- Try to write code so that the same variables and method arguments always have the same type
+- Avoid using `TracePoint` as it can cause YJIT to deoptimize code
+- Avoid using `Binding` as it can cause YJIT to deoptimize code
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.