In drop-on-demand inkjet printheads, ink is pumped steadily through small channels, each of which contains an actuator and a nozzle. When an actuator pulses, a droplet is forced through the nozzle, after which acoustic oscillations reverberate within the channel. Manufacturers would like to damp the residual reverberations, without increasing the pressure drop required to drive the steady flow. In this paper we use gradient-based optimization to show that this can be achieved by constricting the channel where the acoustic velocity is largest and enlarging the channel where the acoustic velocity is smallest. This increases the viscothermal dissipation of the acoustics without changing the viscous dissipation of the steady flow. We separate the compressible Navier–Stokes equations into equations for a steady flow with no oscillations and equations for oscillations with no steady flow. We define two objective functions: the viscous dissipation of the steady flow and the dissipation of the oscillations. We then derive the adjoints for both sets of equations, and obtain expressions for the gradient of each objective function with respect to boundary deformations in Hadamard form. We combine these with a gradient-based optimization algorithm, incorporating constraints such as the shapes of the actuator and nozzle. This algorithm quickly converges to a design that has the same viscous dissipation for the steady flow but a 50 % larger decay rate for the oscillating flow. We show that this design is nearly optimal. It is a shape that inkjet manufacturers, using physical insight and trial and error, have probably not yet considered. We also show how the adjoint fields provide physical insight into the mechanisms affecting each objective function. The main requirements of this method are that the steady flow Mach number and oscillating flow Mach number are small, and that dissipation is dominated by thermoviscous mechanisms. These requirements are often satisfied in microfluidics, so the method in this paper could be applied to many other applications.