Skip to content

Commit cdc1336

Browse files
committed
web: cache pin label margin to avoid per-tile BTerms iteration
Move the max-text-width-across-all-BTerms computation out of getBounds() into computePinLabelMargin(), called from the constructor and eagerInit(). The cached margin (in DBU) is reused on every getBounds() call, avoiding an O(N) iteration over all pins on every tile request. Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent 77e4bc9 commit cdc1336

3 files changed

Lines changed: 47 additions & 19 deletions

File tree

src/web/src/tile_generator.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "color.h"
2222
#include "db_sta/dbSta.hh"
2323
#include "font_atlas.h"
24+
#include "glyph_cache.h"
2425
#include "gui/gui.h"
2526
#include "gui/heatMap.h"
2627
#include "json_builder.h"
@@ -280,6 +281,7 @@ TileGenerator::TileGenerator(odb::dbDatabase* db,
280281
if (chip) {
281282
search_->setTopChip(chip);
282283
}
284+
computePinLabelMargin();
283285
}
284286

285287
TileGenerator::~TileGenerator() = default;
@@ -294,6 +296,29 @@ void TileGenerator::eagerInit()
294296
if (block) {
295297
search_->eagerInit(block);
296298
}
299+
computePinLabelMargin();
300+
}
301+
302+
void TileGenerator::computePinLabelMargin()
303+
{
304+
odb::dbBlock* block = getBlock();
305+
if (!block) {
306+
pin_label_margin_dbu_ = 0;
307+
return;
308+
}
309+
const int pin_size = getPinMaxSize();
310+
if (pin_size <= 0) {
311+
pin_label_margin_dbu_ = 0;
312+
return;
313+
}
314+
int max_text_px = 0;
315+
const auto pin_font = fontAtlasGetFont(kPinLabelFontHeight);
316+
for (odb::dbBTerm* term : block->getBTerms()) {
317+
const int w = pin_font.textWidth(term->getName());
318+
max_text_px = std::max(w, max_text_px);
319+
}
320+
const int label_px = kMinPinNameSizePixels + 3 + max_text_px;
321+
pin_label_margin_dbu_ = label_px * pin_size / kMinPinNameSizePixels;
297322
}
298323

299324
bool TileGenerator::shapesReady() const
@@ -395,25 +420,11 @@ odb::Rect TileGenerator::getBounds() const
395420
odb::Rect bounds;
396421
if (odb::dbBlock* block = getBlock()) {
397422
bounds = block->getBBox()->getBox();
398-
// Expand for pin markers AND labels that extend outside the die edge.
399-
// At the zoom where labels first appear, the label extends
400-
// marker_px + text_margin + text_width pixels
401-
// past the pin anchor. Convert to DBU by dividing by the critical
402-
// scale (= kMinPinNameSizePixels / pin_size).
403-
const int pin_size = getPinMaxSize();
404-
if (pin_size > 0) {
405-
int max_text_px = 0;
406-
const auto pin_font = fontAtlasGetFont(kPinLabelFontHeight);
407-
for (odb::dbBTerm* term : block->getBTerms()) {
408-
const int w = pin_font.textWidth(term->getName());
409-
max_text_px = std::max(w, max_text_px);
410-
}
411-
const int label_px = kMinPinNameSizePixels + 3 + max_text_px;
412-
const int margin = label_px * pin_size / kMinPinNameSizePixels;
413-
bounds.set_xlo(bounds.xMin() - margin);
414-
bounds.set_ylo(bounds.yMin() - margin);
415-
bounds.set_xhi(bounds.xMax() + margin);
416-
bounds.set_yhi(bounds.yMax() + margin);
423+
if (pin_label_margin_dbu_ > 0) {
424+
bounds.set_xlo(bounds.xMin() - pin_label_margin_dbu_);
425+
bounds.set_ylo(bounds.yMin() - pin_label_margin_dbu_);
426+
bounds.set_xhi(bounds.xMax() + pin_label_margin_dbu_);
427+
bounds.set_yhi(bounds.yMax() + pin_label_margin_dbu_);
417428
}
418429
}
419430
return bounds;

src/web/src/tile_generator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,13 @@ class TileGenerator
355355
const Color& c,
356356
int width = 3);
357357

358+
void computePinLabelMargin();
359+
358360
odb::dbDatabase* db_;
359361
sta::dbSta* sta_;
360362
utl::Logger* logger_;
361363
std::unique_ptr<Search> search_;
364+
int pin_label_margin_dbu_ = 0; // cached by computePinLabelMargin()
362365
static constexpr int kTileSizeInPixel = 256;
363366
};
364367

src/web/test/cpp/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,23 @@ gtest_discover_tests(TestDebugGraphics
6262
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
6363
)
6464

65+
add_executable(TestGlyphCache TestGlyphCache.cpp)
66+
67+
target_link_libraries(TestGlyphCache ${TEST_LIBS})
68+
69+
target_include_directories(TestGlyphCache
70+
PRIVATE
71+
${CMAKE_CURRENT_SOURCE_DIR}/../../src
72+
)
73+
74+
gtest_discover_tests(TestGlyphCache
75+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
76+
)
77+
6578
add_dependencies(build_and_test
6679
TestTileGenerator
6780
TestRequestHandler
6881
TestSaveReport
6982
TestDebugGraphics
83+
TestGlyphCache
7084
)

0 commit comments

Comments
 (0)