Related issue reported as a bug: https://osgeo-org.atlassian.net/browse/GEOS-7239
Related commit causing the problem:
This commit has caused an issue with Postgres database because fetching totalFeatures making the request very slow. Postgres fetches count going through all the rows in the table and index helps with vacuum analyze but still, it's not optimal enough and randomly slows down count query. This should have been a format_options (or something else) if you want totalfeatures or not? In my case the postgres was taking 1 minute to get the count of rows (table with 8 million rows with unique index). After vacuum analyze it took ~4 seconds but still without this totalFeatures the geoserver WFS request takes 0.25 milliseconds.
Totalfeatures is not a standard geojson attribute. Nobody looked into this request in last 3 years. I am still struggling and holding back using geoserver 2.2.5 version.