UPDATE
It actually is more gas-efficient to return individual values in certain instances- which removes the need to use an abstract contract in place of a normal interface. For example, if you are deciding to wrap the variables in the struct before returning, you incur extra gas costs due to wrapping them. Here's an example. This is contrary to the original idea that returning one "element" would be cheaper than multiple ones.
// SPDX-License-Identifier: MIT
// Compiled with 0.8.19 with Remix and deployed on Mainnet Fork
pragma solidity ^0.8.0;
contract PersonContract {
struct Person {
string firstName;
string lastName;
uint8 age;
uint256 favNumber;
}
// execution cost: 3356 gas
function getPersonA(
string memory first,
string memory last,
uint256 fav
) public pure returns (Person memory) {
return Person(first, last, 100, fav);
}
// execution cost: 3023 gas
function getPersonB(
string memory first,
string memory last,
uint256 fav
)
public
pure
returns (
string memory,
string memory,
uint8,
uint256
)
{
return (first, last, 100, fav);
}
}