interlynk-io / sbomqs

SBOM quality score - Quality metrics for your sboms
Apache License 2.0
158 stars 20 forks source link

DB performance improvement for compliance code path #265

Closed riteshnoronha closed 1 month ago

riteshnoronha commented 2 months ago

@viveksahu26 found that database is implemented using slices and struct which is very basic way and also a good way for a starting point of view. But the problem is it takes 0(n) time complexity. So, this could take a more time if a sbom has many components(i.e. records). Therefore when replaced this database with more optimized codebase i.e using map, which takes 0(1) time complexity. Therefore I tested both codebase with a Benchmarking test there was huge difference in timing:

Operation Original Database (struct and slice) Optimized Database (maps and mutex)
Benchmark Analysis Number of records to test with: 1000000 Number of records to test with: 1000000
Insert Operation 167.39 milliseconds per operation
42.35 MB allocated
75.18 milliseconds per operation
10.90 MB allocated
GetByKey Operation 709.00 milliseconds per operation
32.26 MB allocated
101.2 nanoseconds per operation
0 B allocated
GetByID Operation 2.6 seconds per operation
32.26 MB allocated
166.7 nanoseconds per operation
0 B allocated

@viveksahu26 great find lets file a separate PR for these changes.