perf: load dependent characters/frames in the separate thread

Seen in #2689
This commit is contained in:
Jindra Petřík
2026-04-06 19:59:08 +02:00
parent 30b0ec4e26
commit f4d54b924c
3 changed files with 65 additions and 26 deletions

View File

@@ -617,6 +617,12 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
*/
@Internal
public String debuggerPackage = null;
/**
* Lock for getting dependent
*/
@Internal
private final Object dependentLock = new Object();
/**
* Imported characterId to SWF map.
@@ -1156,14 +1162,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
* @return Map of characterId to set of dependent characterIds
*/
public Map<Integer, Set<Integer>> getDependentCharacters() {
if (dependentCharacters == null) {
synchronized (this) {
if (dependentCharacters == null) {
computeDependentCharacters();
}
}
synchronized (dependentLock) {
if (dependentCharacters == null) {
computeDependentCharacters();
}
}
return dependentCharacters;
}
@@ -1244,6 +1247,22 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
dependentClassFrames = depCls;
}
/**
* Check if dependent characters are loaded
* @return True if loaded
*/
public boolean isDependentCharactersLoaded() {
return dependentCharacters != null;
}
/**
* Check if dependent frames are loaded
* @return True if loaded
*/
public boolean isDependentFramesLoaded() {
return dependentFrames != null && dependentClassFrames != null;
}
/**
* Gets dependent frames for specified character.
*
@@ -1251,11 +1270,9 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
* @return Set of dependent characterids
*/
public Set<Integer> getDependentFrames(int characterId) {
if (dependentFrames == null) {
synchronized (this) {
if (dependentFrames == null) {
computeDependentFrames();
}
synchronized (dependentLock) {
if (dependentFrames == null) {
computeDependentFrames();
}
}
@@ -1270,7 +1287,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
*/
public Set<Integer> getDependentFramesByClass(String characterClass) {
if (dependentClassFrames == null) {
synchronized (this) {
synchronized (dependentLock) {
if (dependentClassFrames == null) {
computeDependentFrames();
}