xs.remove(x), for xs of type list, has three phases:
- Search
xs for the leftmost occurrence of x (if any).
- If found, “plug the hole”: move every element to the right of the leftmost occurrence one position to the left.
- If not found, raise a
ValueError exception.
Best I can tell, your original fastremove() only skipped step 3. But that’s a trivial expense, tiny constant-time regardless of the length of xs or of the types of its elements. You can sell it on the basis of convenience, but not on speed. If you had benchmarks claiming it was faster, something went wrong (but can’t say more unless you post the actual code used for timing)
The first step takes time proportional to the distance of x from the start of the list. The second proportional to the distance of x from the end of the list. But the second has a much smaller constant factor: it’s only moving pointers around, accessing nothing of the elements’ data or invoking their methods. The first step is much more expensive per element searched, necessarily accessing objects’ data too, and invoking potentially unboundedly expensive comparison methods.
Nothing here addresses the most expensive step: searching for x. If it so happens that your application frequently removes elements appearing very early in the list, then the first step can be much cheaper than the second step, but not true in general. “Plug the hole by filling it with the last element instead” can win big then on speed.
We can’t touch memory at all (whether via memove() or any other way) without the potential of kicking other data out of the cache hierarchy. The first step (searching) is much worse than the second (“plugging the hole”) in this respect, because it not only accesses the memory holding the pointers, but also the data in the objects the pointers point at. They all compete for limited cache resources.
In short, the potential for “speed” here is marginal, addressing only niche cases of the least expensive step, and even then only at the cost of a swapping operation that’s unlike anything else current list methods do. The case is at best weak.
You’d have better luck, I think, pushing for a .discard() method that just suppresses the exception if the element isn’t found. That wouldn’t do anything measurable for speed, but would make some applications a little easier to write.