𝐖𝐡𝐲 𝐄𝐱𝐚𝐜𝐭𝐥𝐲 𝐝𝐨𝐞𝐬 𝐏𝐔𝐁𝐋𝐈𝐂 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 𝐂𝐎𝐒𝐓𝐒 𝐦𝐨𝐫𝐞 𝐆𝐚𝐬 𝐭𝐡𝐚𝐧 𝐄𝐗𝐓𝐄𝐑𝐍𝐀𝐋 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬?
In the case of PUBLIC Functions, arguments of the Functions are copied to 𝐌𝐄𝐌𝐎𝐑𝐘.
While on the other hand, Functions with External visibility can directly read arguments from 𝐂𝐀𝐋𝐋𝐃𝐀𝐓𝐀.
PUBLIC Functions can be called from outside as well as within the contract(Internal Calls). And internal calls are executed via code JUMP as array arguments are passed internally by Pointers to Memory.
Hence, when the compiler generates OPCODES for an internal function, the function expects its arguments to be located in Memory itself.
However, this is not at all the case in EXTERNAL functions. They don't care about Internal Calls at all and thus end up saving some gas.
Don't forget to COMMENT and Share your IDEAS. 𝗟𝗲𝘁'𝘀 𝗟𝗲𝗮𝗿𝗻 𝗮𝗻𝗱 𝗚𝗿𝗼𝘄 𝗧𝗼𝗴𝗲𝘁𝗵𝗲𝗿.