Adding some code would be the same as adding a plugin. A plugin is just code, although some plugins can cause extra bloat on the site if not coded properly or they try to introduce too many features.
You could have a site with 100 plugins on it and have it load quicker than a site with just 10 plugins. It is all dependent on how the plugins interact with the site itself and each other.
If you know of a plugin that would already introduce what you’re looking for, I would suggest using that plugin. If it does slow down the site after using it, you may want to contact the plugin author and mention it to them. In that instance, they may be able to assist further with some configuration options to not include so much and only load what is configured as “active” within the plugin.