It actually not that complicated. HABITAT.
Superimpose the climatic conditions on population density and you'll see it clearly. Climate that support lots of population - I am talking green fertile - generally became populated. You can start from Europe, Asia (India-China-Indonesias) and then Brazil-South America. In Africa - you can go to Nigeria and the likes.
Countries that are dry and arid - like Sahara desert - Arabian desert - large parts of North American - cannot sustain large human population - and are less populated.
Now that historical basis.
Fast forward now. URBANIZATION thanks to Industrilization. COASTAL CITIES account for 80-90% of human population. If the sea was to momentarily flood - it would wipe out huge percentage of human population.
With industrialization and human advancement - cities along the coastline thrived - thanks to international trade. Now most countries have large empty swatch of rural land - with declining population as more and more people move into Cities. Most of these cities are coastal - rarely inland.
What is the future? Industries gave us Cities. Information Tech is giving us remote work/telecomuting/telemedicine.
So we might see urban congested cities become de-congested.
What optimal population size - that I believe is a stupid question. The earth doesn't really create anything. It's not like we are adding weight to earth. Matter can never be created nor destroyed - the same with energy.
Human for example if it can desalinate sea water - will have enough water to support 200B plus people.
Which came first? Population or development?