The bug
Fences are a particularly laggy block due to their often complex geometry (see also MC-123584). For fences where two opposite directions have a connection, it is possible to optimize the geometry such that the game needs to render fewer triangles for effectively the same visual result.
Currently in vanilla, fences use a multipart model consisting of a central post plus one to four outward connection pieces. These outward connections have up to ten faces each, although adjacent block culling often reduces this to eight. For fences which have both north and south connections and/or east and west connections, this adds up to 20 (often culled to 16) faces for the relevant axis. However, it's possible to reduce this to 12 (8) faces with a bit of resource pack magic.
We implement a third model file for each fence, titled [material]_fence_side_long, which defines the two bars stretching from one end of the block to the other via one cuboid per bar, rather than the standard approach which splits it into two elements. The blockstates file for each fence is edited as to not use the standard fence_side in cases where both north and south are true (or both east and west are true), and instead use this specific long side model. As such, with less faces needed for the game to render, we get a visually identical result with less rendering performance impact.
An implementation of this fix is attached in the form of a resource pack. Unless you use Spectator mode or otherwise find yourself intersecting fence blocks, there should be no visual difference from vanilla fences (aside from the fact that this resource pack fixes MC-109478). All fence types are affected by this fix with the exception of bamboo fences, as these use their own texturing system which would require rewriting to work with this fix.
How to reproduce
Create a creative Superflat world with the following preset:
minecraft:barrier;minecraft:the_void
Enter flying mode by double pressing the jump button
Run the command
/tp @s 0 -20 0 0 90
Run the command
/fill -30 -63 -30 30 -56 30 oak_fence
Open the performance graphs via F3+2
Switch between the default resources and the attached resource pack, comparing the performance
Expected results
Good framerates in vanilla.
Actual results
We can do far better.
How to fix
Simply implement the resources in the attached resource pack into vanilla. I give Mojang my full permission and encouragement to use these files to make vanilla Minecraft run better.
You linked the wrong report at the end of the "the bug" section.
Confirmed.