Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-18 - [Optimizing HTML Generation Memory Overhead]
**Learning:** Found O(N^2) string concatenation using `+=` inside large loops in `src/fuzz_introspector/analyses/calltree_analysis.py` causing significant memory reallocation overhead when generating long calltree HTML pages.
**Action:** Replaced string accumulation with `list.append()` followed by `"".join(list)`. Next time, pre-emptively search for large scale string concatenations in HTML generating functions.
20 changes: 11 additions & 9 deletions src/fuzz_introspector/analyses/calltree_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ def html_create_dedicated_calltree_file(
the line it makes sense to have an easy wrapper for other HTML pages
too.
"""
complete_html_string = ""
# Performance Optimization: Replaced O(N^2) string concatenation with O(N) list joins.
complete_html_parts = []
blocker_infos = {}
# HTML start
html_header = html_helpers.html_get_header(
title=f"Fuzz introspector: {profile.identifier}")
html_header += "<div class='content-wrapper calltree-page'>"
html_header += '<div class="content-section calltree-content-section">'
complete_html_string += html_header
complete_html_parts.append(html_header)

# Display fuzz blocker at top of page
if profile.branch_blockers:
Expand All @@ -328,12 +329,12 @@ def html_create_dedicated_calltree_file(
node.cov_ct_idx))] = ""

if fuzz_blocker_table is not None:
complete_html_string += '<div class="report-box">'
complete_html_string += "<h1>Fuzz blockers</h1>"
complete_html_string += fuzz_blocker_table
complete_html_string += "</div>"
complete_html_parts.append('<div class="report-box">')
complete_html_parts.append("<h1>Fuzz blockers</h1>")
complete_html_parts.append(fuzz_blocker_table)
complete_html_parts.append("</div>")

complete_html_string += calltree_html_string
complete_html_parts.append(calltree_html_string)

# HTML end
# close html header and content-section calltree-content-section
Expand All @@ -345,11 +346,12 @@ def html_create_dedicated_calltree_file(
html_end += "</script>"

html_end += '<script src="calltree.js"></script>'
complete_html_string += html_end
complete_html_parts.append(html_end)

complete_html_string += "</body></html>"
complete_html_parts.append("</body></html>")

# Beautify and write HTML
complete_html_string = "".join(complete_html_parts)
soup = bs(complete_html_string, "html.parser")
pretty_html = soup.prettify()
if self.dump_files:
Expand Down
Loading