Let U denote the open unit disc of the complex plane, and φ a holomorphic function taking U into itself. In this paper we study the linear composition operator Cφ
defined by Cφf = f º φ for f holomorphic on U. Our goal is to determine, in terms of geometric properties of φ, when Cφ
is a compact operator on the Hardy and Bergman spaces of φ. For Bergman spaces we solve the problem completely in terms of the angular derivative of φ, and for a slightly restricted class of φ (which includes the univalent ones) we obtain the same solution for the Hardy spaces Hp
(0 < p < ∞). We are able to use these results to provide interesting new examples and to give unified explanations of some previously discovered phenomena.