Building own media library - php mysql - performance

Hi there,
I was wondering if anybody could give me some tips and hints when building my media library.
For the moment, i keep reading my folder and sort the whole arrray to get tree structure.

but it is a bit slow and i would like to rewrite it to gain more performance.
will it be better to store the whole folder tree within the DB and from the db read i go ahead thus avoiding me to always perform a folder read??
other action copy, move, rename, delete go to folder then Db update.

thanks for all the help,
will really apreciate it,

Jerome