# HG changeset patch # User Ludovic Chabant # Date 1434867938 25200 # Node ID 6801ad5aa1d497ac419a77ec160962c82f42f23d # Parent d5724c0c8f1af3fa4ee3546fdc62883ec239d55f internal: Optimize page segments rendering. * Don't create the page data up-front, since it's wasted work if the page has cached rendered segments. * Add a performance counter for data building. diff -r d5724c0c8f1a -r 6801ad5aa1d4 piecrust/app.py --- a/piecrust/app.py Sat Jun 20 23:24:17 2015 -0700 +++ b/piecrust/app.py Sat Jun 20 23:25:38 2015 -0700 @@ -415,6 +415,7 @@ self.env.initialize(self) self.env.registerTimer('SiteConfigLoad') self.env.registerTimer('PageLoad') + self.env.registerTimer("PageDataBuild") @cached_property def config(self): diff -r d5724c0c8f1a -r 6801ad5aa1d4 piecrust/rendering.py --- a/piecrust/rendering.py Sat Jun 20 23:24:17 2015 -0700 +++ b/piecrust/rendering.py Sat Jun 20 23:25:38 2015 -0700 @@ -251,8 +251,6 @@ eis = ctx.app.env.exec_info_stack eis.pushPage(ctx.page, ctx) try: - page_data = _build_render_data(ctx) - ctx.setCurrentPass(PASS_FORMATTING) repo = ctx.app.env.rendered_segments_repository save_to_fs = True @@ -261,11 +259,11 @@ if repo and not ctx.force_render: render_result = repo.get( ctx.uri, - lambda: _do_render_page_segments(ctx.page, page_data), + lambda: _do_render_page_segments_from_ctx(ctx), fs_cache_time=ctx.page.path_mtime, save_to_fs=save_to_fs) else: - render_result = _do_render_page_segments(ctx.page, page_data) + render_result = _do_render_page_segments_from_ctx(ctx) if repo: repo.put(ctx.uri, render_result, save_to_fs) finally: @@ -279,13 +277,19 @@ def _build_render_data(ctx): - data_ctx = DataBuildingContext(ctx.page, page_num=ctx.page_num) - data_ctx.pagination_source = ctx.pagination_source - data_ctx.pagination_filter = ctx.pagination_filter - page_data = build_page_data(data_ctx) - if ctx.custom_data: - page_data.update(ctx.custom_data) - return page_data + with ctx.app.env.timerScope("PageDataBuild"): + data_ctx = DataBuildingContext(ctx.page, page_num=ctx.page_num) + data_ctx.pagination_source = ctx.pagination_source + data_ctx.pagination_filter = ctx.pagination_filter + page_data = build_page_data(data_ctx) + if ctx.custom_data: + page_data.update(ctx.custom_data) + return page_data + + +def _do_render_page_segments_from_ctx(ctx): + page_data = _build_render_data(ctx) + return _do_render_page_segments(ctx.page, page_data) def _do_render_page_segments(page, page_data):