You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exporting static files to downloads is absurdly slow #622
Files are being written at the rate of about one per second. I'm not sure what the story is here (it's possible that it's something wrong with my server), but look into it.
Without a clear direction here, I think optimizations of this sort probably should be moved to Future. This is slow, yes – but we're also cobbling together a lot of XML from strings inside of PHP, which is probably not the most efficient thing in the first place.
I've added a microtime timestamp to the logger so it should be easier to figure out what's taking so long. You can use logger->debug to generate additional messages as well.
OK, I benchmarked this. The bottleneck isn't writing files, it's generating each law.
Structure::list_laws() is the biggest offender. Each law fetched then runs list_laws(), with an individual get_metadata() call for every one of those. We're looking at 100–200 queries per law. So...uh...that'll do it.
Then there's Dictionary::term_list(), which fetches the whole dictionary for every law. Law::render() queries every dictionary term in scope for a given law, and when there are thousands of global terms, that adds up.
Law::render() also creates one PCRE per applicable term, and runs every single one of them over the law to see if there are matches. If there are a couple of thousand globally scoped dictionary terms, that's a lot of queries. I'm surprised at how fast that is, but it's still slow things down.
There are some other causes, but those are the major ones.
Activity
waldoj commentedon Jul 17, 2016
We're just using
file_put_contents()in the export stanza. There's no reasonable optimization to be done there. It's worth checking whether the delay is coming from how we iterate through all of the laws.krusynth commentedon Jul 17, 2016
You'd probably be best off using Xdebug to profile this.
waldoj commentedon Jul 17, 2016
I keep meaning to learn to use that. I guess this is the occasion. :)
krusynth commentedon Jan 15, 2017
Without a clear direction here, I think optimizations of this sort probably should be moved to
Future. This is slow, yes – but we're also cobbling together a lot of XML from strings inside of PHP, which is probably not the most efficient thing in the first place.krusynth commentedon Mar 19, 2017
I've added a microtime timestamp to the logger so it should be easier to figure out what's taking so long. You can use
logger->debugto generate additional messages as well.waldoj commentedon Mar 20, 2017
Oooh, good thinking!
waldoj commentedon Jul 15, 2026
OK, I benchmarked this. The bottleneck isn't writing files, it's generating each law.
Structure::list_laws()is the biggest offender. Each law fetched then runslist_laws(), with an individualget_metadata()call for every one of those. We're looking at 100–200 queries per law. So...uh...that'll do it.Then there's
Dictionary::term_list(), which fetches the whole dictionary for every law.Law::render()queries every dictionary term in scope for a given law, and when there are thousands of global terms, that adds up.Law::render()also creates one PCRE per applicable term, and runs every single one of them over the law to see if there are matches. If there are a couple of thousand globally scoped dictionary terms, that's a lot of queries. I'm surprised at how fast that is, but it's still slow things down.There are some other causes, but those are the major ones.
Speed up listing laws
waldoj commentedon Jul 15, 2026
OK, well, that edit sped things up by about 35%, so that's pretty good.
Memoize term_list()'s structure-scoped bit
waldoj commentedon Jul 15, 2026
Alright, now this is at 56% of the prior query time.
Combine dictionary PCREs into smaller ones
waldoj commentedon Jul 15, 2026
Finally, we're at 38% of the original query time. Basically a tripling of the speed. I'm gonna call this a win.