AFP client seems to be interleave folder enumerations. That means it starts with some enumeration requests:
req1: 40 elements from index 1
reply1: ...
req2: 40 elements from index 41
reply2: ...
req3: 40 elements from index 81
reply3: ...
req4: 40 elements from index 121
reply4: ...
req5: 40 elements from index 161
reply5: ...
req6: 40 elements from index 201
reply6: ...
req7: 40 elements from index 241
reply7: ...
But then another enumeration starts from directory index 1 (leaving out the replies):
req8: 40 elements from index 1
req9: 40 elements from index 41
req10: 40 elements from index 81
req11: 40 elements from index 121
Subsequent requests show both enumerations increment their index mixing up:
req12: 40 elements from index 281
req13: 40 elements from index 321
req14: 40 elements from index 161
req15: 40 elements from index 201
req16: 40 elements from index 361
req17: 40 elements from index 401
Now, every time the index doesn't increment monotonically, like from req 7 to req 8, the afpd process will discard the pre-cached folder enumeration listing and rescan the full directory.
Improve directory enumeration so it's capable of handling request indexes that are not monotonically increasing.
Misread the code, damn.
Interleaved indexes are not a problem at all. It's only a problem when requests for two or more directories are interleaved! Creating a different FR for that.