Don't extract any data you will not be using in the document.
Don't extract all the data each time, but only the new and changed records. This is called incremental loading. If you search this site you can find many discussions on this topic.
Make the source database execute the joins and only retrieve the result that the database generates.
Make sure your machine has enough ram to execute the script successfully. Monitor ram using during the script execution to see if you're hitting the limit of available ram.