Optimal height = height that displays all the rows such that you can't scroll the tableview vertically (assuming elasticity is set to none).
On macOS Catalina and earlier, the optimal height for a headerless NSTableView is:
number of rows * (height of row + height of intercell spacing)
On macOS Big Sur and later, it looks like to be:
number of rows * (height of row + height of intercell spacing) + 20
[Q] Why do we have to add an apparently pointless 20-pixel high white space at the bottom of the NSTableView in macOS Big Sur and later?
This is rather annoying and breaks controls/views spacing.