I recently did major improvements on perfomance on our routines by simply removing the call for trim functions on specific bottlenecks. Please see images attached for a simple example.
I'm using PostgreSQL version 9.5.5-1.pgdg80+1 on Debian 8.6. Someone knows if it's a bug on trim function? Thanks in advance.