Skip to content

Optimize GDBObjPolyFaceMesh.FormatEntity - use integer-based edge tracking - #761

Draft
konard wants to merge 2 commits into
veb86:masterfrom
konard:issue-760-7e6ced7fcd3e
Draft

konard wants to merge 2 commits into
veb86:masterfrom
konard:issue-760-7e6ced7fcd3e

Conversation

@konard

@konard konard commented Feb 13, 2026

Copy link
Copy Markdown

Summary

Optimized GDBObjPolyFaceMesh.FormatEntity procedure to significantly improve rendering performance of PolyFaceMesh entities.

Problem

The original implementation had several performance issues:

  • Used string-based edge tracking with linear search (O(n²) complexity)
  • Repeated IntToStr conversions for each edge comparison
  • Frequent SetLength calls growing array one element at a time
  • Excessive code duplication

Solution

Key optimizations implemented:

  1. Integer-based edge tracking - Replaced string keys with integer comparisons
  2. Pre-allocation - Allocate edge array based on face count (max 4 edges per face)
  3. Vertex count caching - Store VertexArrayInWCS.Count to avoid repeated calls
  4. Early exit - Added check for empty meshes (vertexCount < 2)
  5. Code reduction - Reduced from ~620 lines to ~350 lines

Performance Improvements

  • Eliminated expensive string operations (IntToStr, string concatenation)
  • Reduced memory allocations by pre-allocating array with 256-element chunks
  • Simplified duplicate edge detection with direct integer comparison
  • Maintained correct wireframe rendering according to DXF Polyface Mesh specification

Testing

The algorithm maintains the same rendering logic:

  • Triangle faces: edges (v1-v2), (v2-v3), (v3-v1)
  • Quad faces: edges (v1-v2), (v2-v3), (v3-v4), (v4-v1)
  • Edge visibility based on positive vertex indices
  • Duplicate edge elimination

Issue: #760

Adding .gitkeep for PR creation (created with --gitkeep-file flag).
This file will be removed when the task is complete.

Issue: veb86#760
…cking

Key optimizations:
1. Replace string-based edge tracking with integer-based approach
2. Pre-allocate edge array based on face count
3. Cache vertex count to avoid repeated calls
4. Simplified edge visibility logic
5. Reduced code from 620+ lines to ~350 lines

Performance improvements:
- Eliminated expensive string operations (IntToStr, string concatenation)
- Reduced memory allocations by pre-allocating array
- Simplified duplicate detection with integer comparison
- Added early exit for empty meshes
@konard konard changed the title [WIP] Оптимизируй и ускорь procedure GDBObjPolyFaceMesh.FormatEntity(var drawing:TDrawingDef; var DC:TDrawContext;Stage:TEFStages=EFAllStages); Optimize GDBObjPolyFaceMesh.FormatEntity - use integer-based edge tracking Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant