  Let $K$ be a number field and let $C/K$ be a curve of genus 2 with Jacobian
variety $J$. In this paper, we study the canonical height $\hat{h} \colon J(K)
\to \mathbb R$. More specifically, we consider the following two problems,
which are important in applications:
  (1) for a given $P \in J(K)$, compute $\hat{h}(P)$ efficiently;
  (2) for a given bound $B > 0$, find all $P \in J(K)$ with $\hat{h}(P) \le B$.
  We develop an algorithm running in polynomial time (and fast in practice) to
deal with the first problem. Regarding the second problem, we show how one can
tweak the naive height $h$ that is usually used to obtain significantly
improved bounds for the difference $h - \hat{h}$, which allows a much faster
enumeration of the desired set of points.
  Our approach is to use the standard decomposition of $h(P) - \hat{h}(P)$ as a
sum of local `height correction functions'. We study these functions carefully,
which leads to efficient ways of computing them and to essentially optimal
bounds. To get our polynomial-time algorithm, we have to avoid the
factorization step needed to find the finite set of places where the correction
might be nonzero. The main innovation at this point is to replace factorization
into primes by factorization into coprimes.
  Most of our results are valid for more general fields with a set of absolute
values satisfying the product formula.
  An analogous approach to (1) above for elliptic curves was used in our recent
paper arXiv:1509.08748.
