Here is a simple code snippet for reproduction:
from dolfinx import fem, mesh, common, default_scalar_type
import basix.ufl
import ufl
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
Nx = 100; Ny = 100
msh = mesh.create_rectangle(comm, [np.array([0, 0]), np.array([Nx, Ny])], [Nx, Ny], cell_type=mesh.CellType.triangle, dtype=default_scalar_type)
V = fem.functionspace(msh, basix.ufl.element('CG', msh.basix_cell(), degree=2))
u = ufl.TestFunction(V); v = ufl.TrialFunction(V)
F = ufl.inner(ufl.grad(u), ufl.grad(v))*ufl.dx
lhs, rhs = ufl.lhs(F), ufl.rhs(F)
with common.Timer('Compiling form'):
a, L = fem.form(lhs), fem.form(rhs)
common.list_timings(comm, [common.TimingType.wall])
When I run the script for the first time, the time cost is:
Compiling form | 1 0.320000 0.320000
After the first run, the time cost of subsequent running is negligible:
Compiling form | 1 0.000000 0.000000
And if I change the size of the mesh or if I change the type of cell to quadrilateral, the time cost is still negligible. But if I run the code after a while (this seems to be irregular), the time cost will be large again.
The time difference is more significant in my real application. So I wonder if this is normal and what is the reason for this difference. The dolfinx version I use is 0.9.0 (conda).