Ok, I gave it a go at being even s-m-r-t'er. I took a look at the counts at a bunch of powers of 10:
At 10 totaldigits=11, counts are: [1, 2, 1, 1, 1, 1, 1, 1, 1, 1]
At 100 totaldigits=192, counts are: [11, 21, 20, 20, 20, 20, 20, 20, 20, 20]
At 1000 totaldigits=2893, counts are: [192, 301, 300, 300, 300, 300, 300, 300, 300, 300]
At 10000 totaldigits=38894, counts are: [2893, 4001, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000]
At 100000 totaldigits=488895, counts are: [38894, 50001, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]
At 1000000 totaldigits=5888896, counts are: [488895, 600001, 600000, 600000, 600000, 600000, 600000, 600000, 600000, 600000]
At 10000000 totaldigits=68888897, counts are: [5888896, 7000001, 7000000, 7000000, 7000000, 7000000, 7000000, 7000000, 7000000, 7000000]
A pattern has started to emerge! After 10^n numbers, the counts for 2,3,...,9 are equal to n * 10^(n-1), and the counts for 1 are 1 more than that, n * 10^(n-1) + 1. The counts for 0 are less than the others, and appear to be equal to the total digits at the previous power of ten! So, we can count the digits in the numbers through 10, and then for every power after that, the counts for 1 thru 9 can be computed directly, and the counts for 0 can be obtained from the previous total counts. i.e.:
total_digits_in = {}
total_digits_in[10] = 11
highest_power = 9
for cur_power in range(2, highest_power+1):
counts = [
total_digits_in[10**(cur_power-1)], # zero = total counts at previous power of 10
cur_power * (10**(cur_power - 1)) + 1, # one = n * 10^(n-1) + 1
cur_power * (10 ** (cur_power - 1)) , # 2 thru 9 = n * 10^(n-1)
cur_power * (10 ** (cur_power - 1)),
cur_power * (10 ** (cur_power - 1)),
cur_power * (10 ** (cur_power - 1)),
cur_power * (10 ** (cur_power - 1)),
cur_power * (10 ** (cur_power - 1)),
cur_power * (10 ** (cur_power - 1)),
cur_power * (10 ** (cur_power - 1)),
]
total_digits_in[10**cur_power] = sum(counts)
print(f'Counts for 10^{cur_power}: {counts}')
Counts for 10^2: [11, 21, 20, 20, 20, 20, 20, 20, 20, 20]
Counts for 10^3: [192, 301, 300, 300, 300, 300, 300, 300, 300, 300]
Counts for 10^4: [2893, 4001, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000]
Counts for 10^5: [38894, 50001, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]
Counts for 10^6: [488895, 600001, 600000, 600000, 600000, 600000, 600000, 600000, 600000, 600000]
Counts for 10^7: [5888896, 7000001, 7000000, 7000000, 7000000, 7000000, 7000000, 7000000, 7000000, 7000000]
Counts for 10^8: [68888897, 80000001, 80000000, 80000000, 80000000, 80000000, 80000000, 80000000, 80000000, 80000000]
Counts for 10^9: [788888898, 900000001, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000]
This gets you the exact counts of each digit if going through the integers from 1 through a power of 10, essentially instantly. I think it will be significantly harder to get the counts for an arbitrary number between powers of 10. I don't think it's impossible, just ... difficult. Anyhow, hope you like this new solution!