We examine data on copula duration in dung flies, Scatophaga stercoraria, in relation to female phenotype. We use a marginal value theorem approach based on the plausible mechanisms of sperm competition to predict the effect of female variation on optimal copula duration, t*, from the male perspective. Future fertilizations are expected to have a trivial effect on t* with fully gravid females, but an increasing relative effect on t* towards completion of oviposition, t* is expected to be affected by female size because of variation in (1) a female's egg content, which increases the maximum egg gain available from a mating, and (2) the female reproductive tract, which affects the rate at which sperm are displaced. In fully gravid females, t* was not dependent on egg number variation, but showed a positive relation with egg content in females that had laid a varying proportion of their mature egg load at the time of mating, and were therefore not fully gravid. Our models predict that if a male can estimate egg content only by the distension of a female's abdomen, t* should increase in a similar way to that seen with 'take-over' females. We predict t* for fully gravid females by assuming that males can monitor female size. The data showed that sperm displacement rate decreased, and average egg content increased, with female size. Under two models for a sperm displacement mechanism, one (which assumes indirect displacement at a rate proportional to the increase in spermathecal volume) predicts the observed relation between t* and female size almost exactly. Small males copulated for longer than large males (as predicted and reported previously). (C) 1999 The Association for the Study of Animal Behaviour.