Try a simple data.table
first:
library(data.table)
dt = data.table(d)
# I added xout since I assumed you want that
dt[, list(varXint = spline(tt, varX, xout = seq(1, 4, by = .5))$y,
xout = seq(1, 4, 0.5)),
by = trN]
# trN varXint xout
# 1: 0 1.000000 1.0
# 2: 0 3.166667 1.5
# 3: 0 5.000000 2.0
# 4: 0 6.500000 2.5
# 5: 0 7.666667 3.0
# 6: 0 8.500000 3.5
# 7: 0 9.000000 4.0
# 8: 1 2.000000 1.0
# 9: 1 5.250000 1.5
#10: 1 7.333333 2.0
#11: 1 8.250000 2.5
#12: 1 8.000000 3.0
#13: 1 6.583333 3.5
#14: 1 4.000000 4.0
And if your bottleneck is indeed the inside computation vs just the grouping issue, then check out e.g. multicore and data.table in R or data.table and parallel computing