From 571bfc7402bb05becb00a7ea1b8971ac6ad92d8a Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Wed, 3 Apr 2024 17:28:01 -0400 Subject: [PATCH] YJIT: update code optimization tips in yjit.md (#10445) * YJIT: update code optimization tips in yjit.md * Function => method --- doc/yjit/yjit.md | 10 ++++++---- 1 file 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.