Bash: how to build a aggregated list of file extensions with number of occurrences, sorted

Lately I find myself needing to count the number of files in directory, grouped by extension more and more often. So I started brewing on a solution, also googling a bit here and there. Found something, but that one doesn't work if you have directories with a dot in it, and it wasn't very efficient either if you've got lots of directories and files to count.