Optimization Passes for Your Repo
Published
In the age of LLMs, standardized repos for your codebases can really affect performance. Luckily, ChatGPT can one-shot generating these which is why the code is not provided.
In the age of LLMs, standardized repos for your codebases can really affect performance. Luckily, ChatGPT can one-shot generating these which is why the code is not provided. This is a public list of ideas to help brainstorm things you can do to standardize your repository format.
Imagine you were dropped in a huge repo which you now have to take ownership of the code. When you first do that, you can do as many small refactors as possible to clean up the code to a better state and then going into the refactors of substance.
If you think something should be on this list, please submit a PR to add it!
”You can not pay people enough to accurately review verbose code, and believe me we have tried”
- Some due who worked at Jane Street
Linters
clang-tidyto lint your repos and automatically fix themclang-formatto ensure code is formatted properlyruff formatto format python coderuff check --fixto run a linter over your python code (addIto enableisortwhich is not enabled by default)- use pyupgrade to modernize python definitions. This is something I would personally run manually, though
- Ensure consistency in your repo between
.yamland.yml
Python
- Replacing
os.path.join(os.path.dirname(__file__), "../param/State_Machine.yaml")with pathlib (need to ask ChatGPT to make a custom script for this one) - Use
verminto determine if the minimum python version listed makes sense
C++
- Replacing
#ifndefwith#pragma oncein all header file (yes, I know#pragma onceis non-standard)
ROS Specific Advice
- Ensure a ROS packages’s name (defined in the
package.xml) is the same as the folder name. - Ensure all of your gtest test cases are of the format
test_<test_case_name>instead of<test_case_name>_test. - Ensure if a file contains
class MyNode : public rclcpp::Nodethat it must end in_node - Replacing
this->for the rclcpp core functions with a regexcreate_subscriptioncreate_publisherget_clockcreate_timerget_loggerdeclare_parameter
- Use a CMakeLists toolchain instead of using
--cmake-argsfor colcon - Using the
secondsutility function instead of doingbestpos_msg.header.stamp.sec + bestpos_msg.header.stamp.nanosec * 1e-9you dorclcpp::Time(bestpos_msg.header.stamp).seconds(); - Replacing
get_clock().now()withnow() - Replacing the
.set__<var_name>()with=syntax - Move inline definitions to out of line definitions
Bash
- Use
set -euo pipefailin all your bash scripts - Run
find . -name '*.sh' -exec chmod +x {} +to ensure all bash scripts are executable in your git repo. Asking Chat to ensure they have a shebang before running the find command would also work
Docker
- Use a builder Dockerfile to minimize runtimes size
- Use read-only services when using Dockerfiles
- Add a
.dockerignoresince docker first creates a tar ball of the current directory before building your image (including.gitfolder by default)
General Code Cleanliness
- Make sure it is
README.mdinstead ofreadme.md,READMEor something derivative - Specify the language ```python` in markdown code blocks
Breaking down my personal development setup
Stay in touch
Subscribe to my RSS feed to stay updated
Have any questions
Feel free to contact me! I will answer any and all inquires