Your screenshot shows Photos taking about 244 GB. 244 GB / 40,000 photos is around 6 MB per photo, which is completely reasonable. You need to go to Settings —> Photos and turn on optimize iPhone storage. I have 273 GB of photos/videos in my iCloud Photo Library, but Photos is only 8 GB of space on my phone.