GPS is simply not a good way to measure trail distance. This is because the raw GPS fixes have a lot of noise on them. If you take them literally, then you get a much longer distance than you actually moved. If you low pass filter them too much, you cut off corners and get a shorter distance. The usual algorithm is to apply some low pass filtering, but also not create a new point until it is some minimum distance from the previous point, after filtering. That distance is often a few meters.
How you hold the GPS and what kind of vegetation cover is between you and the sky also matter a lot. For best tracks, put the GPS unit or its antenna on your hat. That way your body doesn't get in the way of the very weak signals from the satellites. If you're really serious about this, get a GPS unit with optional antenna input. Mount the antenna on the top of your hat, then run the wire to where the GPS unit is in your pocket or pack wherever.
A leafy canopy is definitely worse than a nice open sky. I try to do most of my trail mapping from fall to spring when the leaves are down. That helps, but I can still see noticeable difference between the noise on a trail in the woods and walking along a road thru corn fields.
I always take at least two tracks for mapping, one in each direction. That gives me some idea of the error level. In the woods, I can see differences of up to 50 feet (15 meters) sometimes. In one case I walked along a small dirt road thru wide open fields, and I could tell which side of the road I walked on each direction. The maximum error between the two tracks was more like 10 feet.
I use BackCountry Navigator for capturing GPS tracks with a Android tablet. This works surprisingly well. This app allows some tweaking of the GPS filtering. I set it to the minimum distance for a new point that it allows. The GPS distance are usually close enough for casual use, but certainly not as good as real physical measurements.
After capturing GPS tracks with BackCountry Navigator, I import them into the OpenStreeMap editor. There I eyeball-filter them and draw plausible tracks to put the trails on the map. This is where having at least two tracks, one in each direction, helps a lot. After this process, the track lengths as reported by OpenStreetMap are usually not too bad, typically around ±10% from hard-measured.
To really get good trail length measurements, use a measuring wheel. I have a 19 inch wheel that I've added a holder for the GPS to. That helps keep the GPS away from my body, resulting in better tracks than if it were in my pocket or pack. The wheel is consistant to within less than a percent. It's not unusual to have a difference of maybe 4 feet between out and back along 1000 foot trail.
Here is me demonstrating the measuring wheel and tablet capturing a GPS track:

The wooden holder near the top of the handle is something I added. My Android tablet slides into the holder, as can be seen in the picture. This keeps it away from my body while measuring a track. The data is substantially less noisy that way than with the same tablet in a pocket or in my pack.
The wheel has a mechanical counter on it marked in feet and inches. When I get to a trail intersection, I record a waypoint in the BackCountryNavigator software that is taking the GPS track. I use the value on the counter rounded to the nearest foot as the name of the waypoint. That then allows calculating distances later.