We say that a subring R-0 of a ring R is semi-invariant if R-0 is the ring of invariants in R under some set of ring endomorphisms of some ring containing R. We show that R-0 is semi-invariant if and only if there is a ring S superset of R and a set X subset of S such that R-0 = Cent(R)(X) := {r is an element of R: xr = rx for all x is an element of X}; in particular, centralizers of subsets of R are semi-invariant subrings. We prove that a semi-invariant subring R-0 of a semiprimary (resp. right perfect) ring R is again semiprimary (resp. right perfect) and satisfies Jac(R-0)(n) subset of Jac(R) for some n is an element of N. This result holds for other families of semiperfect rings, but the semiperfect analogue fails in general. In order to overcome this, we specialize to Hausdorff linearly topologized rings and consider topologically semi-invariant subrings. This enables us to show that any topologically semi-invariant subring (e.g. a centralizer of a subset) of a semiperfect ring that can be endowed with a "good" topology (e.g. an inverse limit of semiprimary rings) is semiperfect. Among the applications: (1) The center of a semiprimary (resp. right perfect) ring is semiprimary (resp. right perfect). (2) If M is a finitely presented module over a "good" semiperfect ring (e.g. an inverse limit of semiprimary rings), then End(M) is semiperfect, hence M has a Krull-Schmidt decomposition. (This generalizes results of Bjork and Rowen; see Bjork (1971)[5], Rowen (1986, 1987) [23,24].) (3) If rho is a representation of a monoid or a ring over a module with a "good" semiperfect endomorphism ring (in the sense of (2)), then rho has a Krull-Schmidt decomposition. (4) If 5 is a "good" commutative semiperfect ring and R is an S-algebra that is f.p. as an S-module, then R is semiperfect. (5) Let R subset of S be rings and let M be a right S-module. If End(M-R) is semiprimary (resp. right perfect), then End(M-S) is semiprimary (resp. right perfect). (C) 2013 Elsevier Inc. All rights reserved.