avid must have had numbers on his mind. In this Psalm he pointed to a couple of things that were mathematically insurmountable. Ironically, the 2 innumerable things that David mentions would seem to be contrary to one another. In Psalm 40:5 David worships the Lord by pointing out that God's gracious thoughts and intentions toward His children are more in number than we could ever count. Then, in Psalm 40:12 he adds that his troubles were also multiplied beyond his capacity to count them. Now, how can both of those things be true? If God's good ideas concerning us are infinite and our troubles are also seemingly infinite…. where is the disconnect?
We could go to Hebrews 12:11 and interpret the troubles of life as kindnesses... but would that fit with this context? It should instead be pointed out that parts of this passage are definitely Messianic (Psalm 40:6-8 & Hebrews 10:5-7). As such, yes, the innumerable troubles which Christ endured do fit with the innumerable kindnesses in the heart of the Father. Jesus' aches, pains and death were the means of our redemption. Jeremiah 29:11 tells us that God thinks generous thoughts about His people. And yes, even when we are surrounded by a mountain of troubles, we can be certain that God has our good and His glory in His mind and on his heart (Psalm 40:17).