Consider the following code
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (1,1) rectangle (9,9);
\foreach \x in {0,...,10}
\foreach \y in {0,...,10}
{ \draw (\x,\y) circle (1mm); }
\end{tikzpicture}
\end{document}
When compiled with pdfLaTeX, this gives a PDF file of 15 KB. Now let's change the number of circles (the new circles are outside the clipping area):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (1,1) rectangle (9,9);
\foreach \x in {0,...,50}
\foreach \y in {0,...,50}
{ \draw (\x,\y) circle (1mm); }
\end{tikzpicture}
\end{document}
This gives a PDF which takes 139 KB. So the question is
Q: What does the clip
command do with the content outside the clipping area? The above experiment suggests that all the circles are in fact there, but some of them are invisible. Is the clipping made on the side of the PDF viewer or on the side of the compiler? And is there a way to optimize the result by means of TikZ? If no, how should one proceed?