summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maximechevalierb@gmail.com>2021-05-06 15:39:28 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:34 -0400
commit6c793a2fed4592d2196d9e43df58fba9274faafb (patch)
treebcd1af34578b1a15a4e56147068b896ee8010a91 /README.md
parent4f24f3afc7baed2294614357486e10e1f055c661 (diff)
downloadruby-6c793a2fed4592d2196d9e43df58fba9274faafb.tar.gz
Update README.md
Diffstat (limited to 'README.md')
-rw-r--r--README.md4
1 files changed, 3 insertions, 1 deletions
diff --git a/README.md b/README.md
index 76b9ba40d3..b60022ce3c 100644
--- a/README.md
+++ b/README.md
@@ -92,16 +92,18 @@ 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 fast on YJIT. Some of this advice is based on current limitations of YJIT, while other advice is broadly applicable. It may not 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 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, 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.
- 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
You can also compile YJIT in debug mode and 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.