I am building a library to help developers to create generative art in Solidity. I'd like to add a lot of features (internal methods) to this library to make it easy to create a variety of art.

I'm wondering if the Solidity linker is able to eliminate unused library methods.

Let's assume we have a library Foo with 100 methods.

library Foo {
  function method1() pure internal { ... }
  function method2() pure internal { ... }
  function method100() pure internal { ... }

If somebody creates a smart contract, which uses only method1 of library Foo, does it bring all the code into the contract inlcuding unsed method2 to method100?

In most of modern development environments (such as C++, Swift, C#), the linker is smart enough to eliminate unsed code. I am wondering if the Solidity linker is able to perform such an optimization.

  • So your question is :"Does solidity optimizer removes unused internal functions ". I think the answer is no, that isn't how the optimizer should work. But best answer might be to test it. By writing contract with a large number of unused internal functions.
    – Sky
    Nov 6, 2022 at 16:25

1 Answer 1


The Solidity optimizer does eliminate definitions of all functions that are never referenced through a step called UnusedPruner. It also generally does not include uncalled internalized functions, including library functions, into the bytecode.




  • Why do you say "generally"? Under which circumstances are unused internal functions not removed? Unused functions not consistently being removed is something that I've experienced. Would private functions definitely be removed?
    – MShakeG
    Mar 16 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.