Decorator memory reduction backport

pull request (should probably go to a testing branch first)