Performance enhancement for instance sorting - done only on demand

This commit is contained in:
Matthias Koefferlein 2023-09-10 19:47:43 +02:00
parent e2fa88fcfb
commit b7ee16b63f
3 changed files with 25 additions and 9 deletions

View File

@ -92,7 +92,8 @@ Cell::box_type Cell::ms_empty_box = Cell::box_type ();
Cell::Cell (cell_index_type ci, db::Layout &l) Cell::Cell (cell_index_type ci, db::Layout &l)
: db::Object (l.manager ()), : db::Object (l.manager ()),
m_cell_index (ci), mp_layout (&l), m_instances (this), m_prop_id (0), m_hier_levels (0), m_bbox_needs_update (false), m_ghost_cell (false), m_cell_index (ci), mp_layout (&l), m_instances (this), m_prop_id (0), m_hier_levels (0),
m_instances_need_sort (false), m_instances_need_sort_box_tree (false), m_bbox_needs_update (false), m_ghost_cell (false),
mp_last (0), mp_next (0) mp_last (0), mp_next (0)
{ {
// .. nothing yet // .. nothing yet
@ -131,6 +132,10 @@ Cell::operator= (const Cell &d)
m_prop_id = d.m_prop_id; m_prop_id = d.m_prop_id;
m_bbox_needs_update = d.m_bbox_needs_update; m_bbox_needs_update = d.m_bbox_needs_update;
// need to update the instances inst_by_cell_index pointers
m_instances_need_sort = true;
m_instances_need_sort_box_tree = true;
} }
return *this; return *this;
} }
@ -613,6 +618,8 @@ Cell::invalidate_insts ()
{ {
mp_layout->invalidate_hier (); // HINT: must come before the change is done! mp_layout->invalidate_hier (); // HINT: must come before the change is done!
mp_layout->invalidate_bboxes (std::numeric_limits<unsigned int>::max ()); mp_layout->invalidate_bboxes (std::numeric_limits<unsigned int>::max ());
m_instances_need_sort = true;
m_instances_need_sort_box_tree = true;
m_bbox_needs_update = true; m_bbox_needs_update = true;
} }
@ -700,7 +707,10 @@ Cell::clear_parent_insts (size_t sz)
void void
Cell::sort_child_insts () Cell::sort_child_insts ()
{ {
m_instances.sort_child_insts (); if (m_instances_need_sort) {
m_instances.sort_child_insts ();
}
m_instances_need_sort = false;
} }
std::pair<bool, db::pcell_id_type> std::pair<bool, db::pcell_id_type>
@ -744,9 +754,12 @@ Cell::change_pcell_parameters (const instance_type &ref, const std::vector<tl::V
} }
void void
Cell::sort_inst_tree () Cell::sort_inst_tree (bool force)
{ {
m_instances.sort_inst_tree (mp_layout); if (force || m_instances_need_sort_box_tree) {
m_instances.sort_inst_tree (mp_layout);
}
m_instances_need_sort_box_tree = false;
// update the number of hierarchy levels // update the number of hierarchy levels
m_hier_levels = count_hier_levels (); m_hier_levels = count_hier_levels ();

View File

@ -1076,7 +1076,9 @@ private:
db::properties_id_type m_prop_id; db::properties_id_type m_prop_id;
// packed fields // packed fields
unsigned int m_hier_levels : 29; unsigned int m_hier_levels : 28;
bool m_instances_need_sort : 1;
bool m_instances_need_sort_box_tree : 1;
bool m_bbox_needs_update : 1; bool m_bbox_needs_update : 1;
bool m_ghost_cell : 1; bool m_ghost_cell : 1;
@ -1147,9 +1149,9 @@ private:
* This will sort the cell instance list. As a prerequesite * This will sort the cell instance list. As a prerequesite
* the cell's bounding boxes must have been computed. * the cell's bounding boxes must have been computed.
* *
* @param layers The maximum number of layers in the child cells * @param force Force sorting, even if not strictly needed
*/ */
void sort_inst_tree (); void sort_inst_tree (bool force);
}; };
/** /**

View File

@ -1799,8 +1799,9 @@ Layout::do_update ()
for (bottom_up_iterator c = begin_bottom_up (); c != end_bottom_up (); ++c) { for (bottom_up_iterator c = begin_bottom_up (); c != end_bottom_up (); ++c) {
++*pr; ++*pr;
cell_type &cp (cell (*c)); cell_type &cp (cell (*c));
if (hier_dirty () || dirty_parents.find (*c) != dirty_parents.end ()) { bool force_sort_inst_tree = dirty_parents.find (*c) != dirty_parents.end ();
cp.sort_inst_tree (); if (hier_dirty () || force_sort_inst_tree) {
cp.sort_inst_tree (force_sort_inst_tree);
} }
if (cp.layers () > layers) { if (cp.layers () > layers) {
layers = cp.layers (); layers = cp.layers ();