To take a more modern example, the same is true about compulsory military service. Many people once believed and many still believe that conscription is simply way cheaper than voluntary military service. However, the people that are drafted into the military service could instead have been involved in the productive work in the regular economy, and paying taxes that may be used to pay volunteers.
In short, "pure economics" doesn't automatically go in favour of slavery.
Slavery was a sustainable institution not just because it was perceived as cost-efficient. It required general acceptance of the idea that it's OK to deny certain classes of people -- e.g., according to their origin -- their basic rights. And that is pretty much about racism.