user77936: I'm working on a project with a Digispark ATTiny85, that performs keystrokes using the DigisparkKeyboard library (https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkKeyboard). Besides the DigiKeyboard, I also import EEPROM.h.
My own code is only about 150 lines, I've cut down the size following a number of online guides, trying to avoid larger data types and so on. The Digispark is limited to ~6kB and the imported DigiKeyboard library takes up a little more that 5.4kB. In total the compiled project takes up about 7kB, which exceeds the boards capacity.
From the DigiKeyboard library I only use DigiKeyboard.sendKeyStroke() and DigiKeyboard.print() (with about only ten different characters). So I assume there is a lot of unused code I could remove, but I don't know how to approach this. I use Visual Studio Code and PlatformIO.
How could I reduce the size of the used DigisparkKeyboard library?

user31105: The compiler/linker will remove unused functions/methods automatically, so I doubt you can save memory by removing unused functions/methods yourself.
However, you could possibly gain by:

Removing the calls of check functions/methods when you know the result will be always false, true, or always the same number, string or data type in general.
Removing (parts of) functions/methods which are related to physical or logical functionality you never use. Like e.g. if, case statements that will never apply).
Prevent using an entire class (e.g. String) (see second comment of Emma Makes below).


user77936: With input from @EdgarBonet, I looked into the functions used and it turned out that the String() function, I used once in my code, takes up about 3kB of space in the compiled program.
I ended up removing the line with String() and kept the imported DigiKeyboard library as it is.

77936: <p>I'm working on a project with a Digispark ATTiny85, that performs keystrokes using the DigisparkKeyboard library (<a href="https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkKeyboard" rel="nofollow noreferrer">https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkKeyboard</a>). Besides the DigiKeyboard, I also import EEPROM.h.</p>
<p>My own code is only about 150 lines, I've cut down the size following a number of online guides, trying to avoid larger data types and so on. The Digispark is limited to ~6kB and the imported DigiKeyboard library takes up a little more that 5.4kB. In total the compiled project takes up about 7kB, which exceeds the boards capacity.</p>
<p>From the DigiKeyboard library I only use <code>DigiKeyboard.sendKeyStroke()</code> and <code>DigiKeyboard.print()</code> (with about only ten different characters). So I assume there is a lot of unused code I could remove, but I don't know how to approach this. I use Visual Studio Code and PlatformIO.</p>
<p>How could I reduce the size of the used DigisparkKeyboard library?</p>
 31105: <p>The compiler/linker will remove unused functions/methods automatically, so I doubt you can save memory by removing unused functions/methods yourself.</p>
<p>However, you could possibly gain by:</p>
<ul>
<li>Removing the calls of check functions/methods when you know the result will be always <code>false</code>, <code>true</code>, or always the same number, string or data type in general.</li>
<li>Removing (parts of) functions/methods which are related to physical or logical functionality you never use. Like e.g. <code>if</code>, <code>case</code> statements that will never apply).</li>
<li>Prevent using an entire class (e.g. <code>String</code>) (see second comment of Emma Makes below).</li>
</ul>
 77936: <p>With input from @EdgarBonet, I looked into the functions used and it turned out that the <code>String()</code> function, I used once in my code, takes up about 3kB of space in the compiled program.</p>
<p>I ended up removing the line with <code>String()</code> and kept the imported DigiKeyboard library as it is.</p>
