Commit 95b0ad5
Shangmin Dou
<fix>[core]: redesign StringSimilarity to match fmt template first
Redesign findSimilar() with a three-phase strategy to prevent
performance degradation when operr() format args contain very
long strings (e.g., serialized ErrorCodeList or HTML bodies):
Phase 1: regex match against raw fmt template (always short).
Phase 2: fallback to formatted string only if Phase 1 misses
and length <= maxElaborationRegex (8192).
Phase 3: distance match always uses raw fmt template.
Also add length guard in findMostSimilarRegex() and remove
redundant String.format length check in Platform.elaborate().
Root cause: StringSimilarity.findSimilar() was running 199
regex patterns via ReTree against multi-KB formatted strings,
causing 7+ second latency in error code creation hot paths.
Resolves: ZSTAC-72079
Change-Id: I38b98a762deb436da31e4884da05d12b38b98a761 parent c05b8f7 commit 95b0ad5
2 files changed
Lines changed: 41 additions & 14 deletions
File tree
- core/src/main/java/org/zstack/core
- utils/src/main/java/org/zstack/utils/string
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
938 | 938 | | |
939 | 939 | | |
940 | 940 | | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | 941 | | |
946 | 942 | | |
947 | 943 | | |
| |||
Lines changed: 41 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
290 | 299 | | |
291 | 300 | | |
292 | 301 | | |
| |||
311 | 320 | | |
312 | 321 | | |
313 | 322 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
| 323 | + | |
| 324 | + | |
318 | 325 | | |
319 | 326 | | |
320 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
321 | 339 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
327 | 354 | | |
328 | 355 | | |
329 | 356 | | |
330 | | - | |
| 357 | + | |
331 | 358 | | |
332 | 359 | | |
333 | 360 | | |
| |||
355 | 382 | | |
356 | 383 | | |
357 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
358 | 389 | | |
359 | 390 | | |
360 | 391 | | |
| |||
0 commit comments