Method and system for deduplication and reuse of resources during Android operation

By intercepting resource loading requests in the Android system and using the global cache pool for resource identifier query and classification reuse, the compilation error problem caused by resource redundancy in large Android projects is solved, improving development efficiency and application stability.

CN120803443APending Publication Date: 2025-10-17CHUXINHUDONG

Patent Information

Application Number
CN202511269715.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-08
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

In large-scale Android projects, compilation errors caused by resource redundancy frequently occur. Manual troubleshooting is inefficient and error-prone, and existing technologies cannot effectively solve this problem.

Method used

Resource loading requests are intercepted through the hook mechanism, unique resource identifiers are calculated, and the global resource cache pool is used for query and reuse. Resources are classified and corresponding strategies are implemented to avoid repeated loading.

Benefits of technology

It improves resource management efficiency, ensures application visual presentation and functional consistency, reduces manual troubleshooting time and costs, and avoids UI rendering anomalies and memory redundancy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803443A_ABST
    Figure CN120803443A_ABST
Patent Text Reader

Abstract

The invention discloses a resource deduplication and reuse method and system during Android operation, relates to the technical field of resource deduplication, and is different from an inertial mode for solving conflicts in a compilation period in the prior art. And finally, redirecting to the same memory instance or deriving from the same constant state object. According to the method, the certainty and the consistency of visual presentation and functional behaviors of the application are fundamentally ensured, and a series of potential operation defects such as UI rendering abnormity, asynchronous object states and unnecessary redundancy of a memory which are possibly caused by accidental loading of resources with the same name but different contents or repeated instantiation of resources with the same content but different paths are eradicated; the tedious and low-efficiency manual troubleshooting and modification links are avoided, the debugging period caused by resource problems is greatly shortened, and the labor cost and the time cost are remarkably saved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of resource deduplication, and particularly relates to an Android runtime resource deduplication and reuse method and system. BACKGROUND

[0002] Resource files are the basis for Android application development and iteration. However, in large projects or complex scenarios of multi-module integration, redundant resources with repeated content or name conflicts may exist in the application project due to human negligence or third-party library dependency conflicts. Generally, the Android resource packaging tool will detect these redundant resources during the application packaging and compilation stage and interrupt the packaging process in the form of a compilation error, resulting in the failure to correctly generate an application installation package. The general developer's solution is to return to the project source code to check, compare and delete one by one according to the error information thrown by the compilation tool. However, this manual checking technique has significant shortcomings: when the application is large and the resource correlation is complex, the compilation may throw hundreds of resource errors at a time, and the efficiency of manual positioning and modification is extremely low, so as to waste a lot of development time; the checking process is not only tedious, but also requires the developer to have a clear understanding of resource dependencies, otherwise, it is easy to delete by mistake and introduce new potential problems. Therefore, this processing method will seriously waste valuable human resources and slow down the overall efficiency of development and debugging when facing a large number of resource errors. SUMMARY

[0003] In view of the defects in the prior art, the application provides an Android runtime resource deduplication and reuse method and system to solve the above technical problems.

[0004] An Android runtime resource deduplication and reuse method, comprising the following steps: intercepting a target resource loading request generated by a program runtime through a hook mechanism; calculating a unique resource identifier corresponding to the intercepted target resource; querying in a preset global resource cache pool based on the unique resource identifier; the global resource cache pool is a key-value pair set, wherein the key is the unique resource identifier and the value is a loaded resource; if a loaded resource matching the unique resource identifier is found in the global resource cache pool, then classifying resources based on a constant state object of the loaded resource, implementing a reuse strategy according to the classification result, and terminating the original target resource loading process; if no loaded resource matching the unique resource identifier is found in the global resource cache pool, then calling a target resource loading process to create a new loaded resource, and storing the new loaded resource and the unique resource identifier in the global resource cache pool in the form of a key-value pair.

[0005] As preferred, when classifying the loaded resource based on the constant state object of the loaded resource, the following steps are specifically adopted: If the loaded resource is a resource for responding to an interactive state or a resource for responding to a numerical change, it is classified as a built-in state type object; If the loaded resource does not belong to the built-in state type object, the constant state object of the loaded resource is obtained, the variable flow of the constant state object is called, and the numerical value of the variable configuration identifier is obtained; If the numerical value of the variable configuration identifier is not zero, it is classified as a variable variant type object; If the numerical value of the variable configuration identifier is zero, it is classified as a stable type object.

[0006] As preferred, when implementing the reuse strategy according to the classification result, if the cached resource is a built-in state type object, a built-in state type reuse strategy is executed: Obtain the constant state object of the built-in state type object; Call the variable flow of the constant state object to create a brand new drawable object instance; Return the brand new drawable object instance.

[0007] As preferred, when implementing the reuse strategy according to the classification result, if the cached resource is a stable type object, a stable type reuse strategy is executed: In a preset shared instance cache, a shared instance associated with the constant state object of the stable type object is searched; If the shared instance exists, the shared instance is directly returned as the reuse result; If the shared instance is not found, a new drawable object instance is created through the constant state object, the drawable object instance is stored in the shared instance cache as a new shared instance, and the new shared instance is returned.

[0008] As preferred, when the numerical value of the variable configuration identifier is not zero, the loaded resource is classified as a variable variant type object, the following classification steps are further included: A lightweight convolution module is used to extract content feature data of the loaded resource to generate key features; The comparison distance between the key features and a preset active comparison feature set is calculated, and based on the comparison distance, an activity score is obtained using a Softmax activation function; If the activity score is greater than a preset activity threshold, the loaded resource is classified as a high variable variant type object; If the activity score is less than the preset activity threshold, the loaded resource is classified as a slow variable variant type object.

[0009] Preferably, when implementing a reuse strategy based on the classification results, if the cached resource is a highly variable object, a highly variable reuse strategy is executed: Obtaining a constant state object of the highly variable object; Calling the constant state object to create a new drawable object instance; Performing depth state independence processing on the new drawable object instance, wherein the depth state independence processing specifically comprises: sequentially calling at least two processes for achieving state independence, including at least one state independence process and one state reset process; Returns the drawable object instance after the depth state independence processing.

[0010] Preferably, when implementing a reuse strategy based on the classification result, if the cached resource is a slowly mutating object, the slowly mutating reuse strategy is executed: Obtaining a constant state object of the slowly mutating object; Calling the constant state object to create a new drawable object instance; Performing standard state independence processing on the new drawable object instance, wherein the standard state independence processing specifically includes: calling at least one process for achieving state independence; Returns the drawable object instance after the standard state independence processing.

[0011] Preferably, the following method is used to calculate the corresponding unique resource identifier: Obtaining the binary data stream of the target resource; Based on the MD5 message digest algorithm, a unique hash value is generated for the binary data stream, and the hash value is used as the unique resource identifier of the target resource.

[0012] Preferably, when the number of entries in the global resource cache pool reaches a preset threshold, a least recently used algorithm is used to remove resource objects in the cache pool.

[0013] An Android runtime resource deduplication and reuse system, including the following: The interception module is used to intercept the target resource loading request generated by the program during runtime through the hook mechanism; An identifier generation module, connected to the interception module, for calculating a corresponding unique resource identifier according to the intercepted target resource loading request; A cache management module, connected to the identifier generation module, the cache management module including a global resource cache pool; The global resource cache pool is a key-value pair set, wherein the key is the unique resource identifier and the value is the loaded resource; The cache management module is further configured to: query the global resource cache pool based on the unique resource identifier, and if a matching loaded resource is found, directly return the loaded resource for reuse and terminate the original target resource loading process; An execution module, connected to the cache management module, for calling the original target resource loading process to create a new loaded resource when no matching loaded resource is found; The cache management module is further configured to: after the resource loading execution module creates the new loaded resource, store the new loaded resource and the unique resource identifier in the global resource cache pool in the form of a key-value pair.

[0014] The beneficial effect of the present invention is that this method is different from the conventional mode of resolving conflicts at compile time in the prior art. Any loading request for logically equivalent resources will eventually be redirected to the same memory instance or derived from the same constant state object. This fundamentally ensures the certainty and consistency of the application's visual presentation and functional behavior, eradicating a series of potential operational defects such as UI rendering anomalies, object state asynchrony, and unnecessary memory redundancy caused by the accidental loading of resources with the same name but different contents, or multiple instantiations of resources with the same content but different paths. This bypasses the tedious and inefficient manual troubleshooting and modification process, greatly shortens the debugging cycle caused by resource issues, and significantly saves labor and time costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0016] Figure 1 A schematic diagram of a flow chart of a method for deduplicating and reusing resources during Android runtime provided by the present invention; Figure 2 This is a structural diagram of an Android runtime resource deduplication and reuse system provided by the present invention. DETAILED DESCRIPTION

[0017] In the description of the present application, it needs to be understood that the terms "center", "longitudinal", "transverse", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, which are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the present application.

[0018] The following disclosure provides many different embodiments or examples for implementing different structures of the application. For the purpose of simplifying the present application, the components and settings of specific examples are described below. Of course, they are only examples and the purpose is not to limit the present application.

[0019] The embodiments of the application will be described in detail below with reference to the accompanying drawings.

[0020] As Figure 1 shown, an Android runtime resource deduplication and reuse method includes the following steps: Intercepting a target resource loading request generated by a program runtime through a hook mechanism; For the intercepted target resource, calculating a corresponding unique resource identifier thereof; In a preset global resource cache pool, querying based on the unique resource identifier; the global resource cache pool is a key-value pair set, wherein the key is the unique resource identifier and the value is a loaded resource; If a loaded resource matching the unique resource identifier is found in the global resource cache pool, classifying resources based on a constant state object of the loaded resource, and implementing a reuse strategy according to the classification result, while terminating the original target resource loading process; If no loaded resource matching the unique resource identifier is found in the global resource cache pool, calling a target resource loading process to create a new loaded resource, and storing the new loaded resource and the unique resource identifier in the global resource cache pool in the form of a key-value pair.

[0021] In the initial stage of application startup, the method intercepts the key method of the core component responsible for loading resources in the Android system bottom layer through Hook technology such as injection code or dynamic proxy. When the upper application initiates any resource loading request, the interception layer will first take over the processing flow. It will read the original binary data stream of the resource according to the requested resource ID, and use MD5 and other efficient information digest algorithms to calculate a hash value that can uniquely represent the content of the data stream, that is, a unique resource identifier. Then, the system uses this hash value as a key to query in the high-speed memory cache pool. If the query hits, it means that a resource with the same content has been loaded in the previous running, and the system immediately suspends the native loading process and intelligently classifies and reuses the constant state object of the resource in the cache, thereby directly returning a safe and correct resource instance. If the query does not hit, it means that it is a new resource content, and the system will release and execute the original loading process. After the resource is loaded successfully, it is stored in the cache pool together with the calculated hash value for subsequent reuse requests. This method is different from the conventional mode of solving conflicts at the compilation stage, bypassing the tedious, inefficient and error-prone manual inspection and modification process, so that application packages containing a large number of redundant resources can also be successfully built and stably run. Any loading request for logically equivalent resources will ultimately be redirected to the same memory instance or derived from the same constant state object. This fundamentally ensures the determinacy and consistency of application visual presentation and functional behavior, and eliminates a series of potential running defects such as UI rendering abnormalities, object state asynchronization, and unnecessary memory redundancy that may be caused by accidentally loading resources with the same name but different contents, or instantiating resources with the same content but different paths multiple times. This greatly shortens the debugging period caused by resource problems, and significantly saves labor costs and time costs.

[0022] More specifically, when classifying resources based on the constant state object of the loaded resource, the following steps are specifically adopted: If the loaded resource is a resource for responding to an interactive state or a resource for responding to a numerical change, it is classified as a built-in state type object; If the loaded resource is not a built-in state type object, the constant state object of the loaded resource is obtained, the variable flow of the constant state object is called, and the numerical value of the variable configuration identifier is obtained; If the numerical value of the variable configuration identifier is not zero, it is classified as a variable type object; If the numerical value of the variable configuration identifier is zero, it is classified as a stable type object.

[0023] In the implementation process, first, the keyword is checked whether the resource object is used for responding to the state list of the interactive state such as click, focus or the level list of the level change, which are both the state container types built in the system. If yes, it is classified as a built-in state type. The beneficial effect of this step is that it can immediately identify those resources that contain complex state machines themselves and cannot share the same instance among multiple UI components, thereby forcing the creation of a completely new and state-independent instance for it, thus eliminating the UI logic error of one button press, all button linkage caused by instance sharing from the source. Then, if the resource does not belong to the above type, the system will call its constant state method to obtain a constant state object that can represent all its invariant attributes. Then, call the get variable configuration method of the constant state object to get an integer identification value representing the variable configuration. This method can reflect whether the configuration information of the resource may change at runtime, and its role is to make the state independent or vary, and return the new instance after state-independent processing to the requester. Any modification made by the subsequent calling party will be strictly limited within this independent instance. Then, the system judges the value, if it is zero, it means that the appearance of the resource is not affected by any device configuration change, and is completely static, so it is classified as stable. This process identifies the safest and globally shared resource at a very low cost, allowing the system to reuse it in singleton mode, that is, only one shared instance is retained throughout the application lifecycle, which maximizes the memory overhead and processor overhead of object creation, and is the most efficient reuse strategy. On the contrary, if the value is not zero, it proves that the appearance of the resource will change at least with the change of a certain configuration, and has potential variation risk, so it is classified as variable. It accurately identifies those resources that appear to be stable but are actually sensitive, avoiding visual confusion problems caused by reusing the same cache instance in different interface contexts, and providing a decision basis for subsequent safer and more isolated reuse strategies.

[0024] More specifically, according to the classification result, when implementing the reuse strategy, if the cached resource is a built-in state type object, the built-in state type reuse strategy is executed: Obtain the constant state object of the built-in state type object; Call the variable flow of the constant state object to create a new drawable object instance; Return the new drawable object instance.

[0025] When the system identifies a cached resource as a built-in stateful, it will first call the cached object's get constant state method. This operation will return a constant state object as the resource core prototype, which encapsulates all the immutable properties of the resource, such as the included images, colors, etc. Then, the system will immediately call the create new drawable object method of this constant state object. This method will take the constant state object as a blueprint and build a brand new drawable object instance in memory with the same appearance properties as the original object in the cache, but with a completely independent state machine.

[0026] More specifically, when implementing the reuse strategy according to the classification result, if the cached resource is a stable object, the stable reuse strategy is executed: In the preset shared instance cache, the shared instance associated with the constant state object of the stable object is searched; If the shared instance exists, the shared instance is directly returned as the reuse result; If the shared instance is not found, a new drawable object instance is created through the constant state object, the drawable object instance is stored in the shared instance cache as a new shared instance, and the new shared instance is returned.

[0027] When a cached resource is confirmed to be stable, the system will start a singleton reuse strategy based on shared instances. First, use the constant state object of the stable object as a unique key to query in the globally unique shared instance cache specially preset for stable resources. If the query hits, it means that the singleton object of the resource has been created before, and the system will directly return this existing shared instance, which is the most efficient reuse path. If the query does not hit, it means that this is the first loading request of the stable resource in this application running period. At this time, the system will call the create new drawable object method of the constant state object to generate the first and only shared instance of the resource. Then, the newly created instance is immediately stored in the shared instance cache and associated with its constant state object. Finally, the newly created shared instance is returned as the result.

[0028] More specifically, if the value of the variable configuration identifier is not zero, the following classification steps are included when classifying it as a variable variant object: Lightweight convolution modules are used to extract content feature data of the loaded resource to generate key features; The comparison distance between the key features and the preset active comparison feature set is calculated, and based on the comparison distance, the active degree score is obtained using the Softmax activation function; If the active degree score is greater than the preset active degree threshold, the loaded resource is classified as a high variable variant object; If the activity score is less than a preset activity threshold, the loaded resource is classified as a slow variable object.

[0029] The process of calculating the variability score includes: calculating the matching depth of the key feature and all matching features in the activity matching feature set, and integrating all matching depths into a training set; after the training set is processed by the Softmax activation function, the maximum value of the output is taken as the variability score of the key feature; The matching distance is the Euclidean distance, which is calculated by a deep neural network, and the training steps of the deep neural network are as follows: All matching features of the activity data set are obtained to establish an activity matching feature set; All associated features meeting the preset activity correlation degree are screened out to form an activity feature set; The deep neural network is used to calculate the loss between the activity feature set and the activity matching feature set, and the loss is back-propagated to train the backbone network of the deep neural network; The backbone network of the deep neural network is a first convolutional module stacked by multiple convolutional layers, and the lightweight convolutional module includes a second convolutional module for feature recognition of the associated features and a fully connected layer.

[0030] The system scans and analyzes the visual content of the loaded resource, extracts content feature data that can represent its core design elements, and compresses it into a set of key feature vectors. Then, the system compares this key feature with a pre-set activity matching feature set, which stores a large number of features of problem samples known to be prone to visual problems when configuration changes. The comparison here is not a simple numerical comparison, but a pre-trained deep neural network is used to calculate the Euclidean distance between the key feature and each matching feature in the feature set, thereby obtaining a set of quantitative difference matching depth values. Next, the set of matching depth values is integrated and input into a flexible maximum value activation function for normalization processing, and the maximum value of the output result is defined as the activity score of the resource. Finally, the activity score is compared with a preset activity threshold to further quantify the degree of change and the risk of visual defects.

[0031] More specifically, when implementing the reuse strategy according to the classification result, if the cached resource is a high variability object, a high variability reuse strategy is executed: A constant state object of the high variability object is obtained; The constant state object is called to create a new drawable object instance; The new drawable object instance is subjected to a deep state independence process, which specifically comprises sequentially invoking at least two state independence processes, at least one state independence process and one state reset process. The drawable object instance subjected to the deep state independence process is returned.

[0032] When the system needs to reuse a cached highly variable resource, it first acquires its constant state object and creates a new drawable object instance based on the constant state object. However, the new instance is not immediately returned for use, but is subjected to a deep state independence process. The process includes at least two consecutive processes with different purposes: the first step is to execute a state independence process, which aims to perform a complete deep copy of the internal core data of the new instance to ensure that all variable components inside the new instance are completely copied, such as graphic paths, gradient definitions, and even nested drawable objects. Thus, any underlying data sharing with the original constant state object is cut off; the second step is to execute a state reset process, which is responsible for forcibly restoring all state attributes of the data to their initial default values.

[0033] More specifically, when implementing the reuse strategy according to the classification result, if the cached resource is a slow variable object, a slow variable reuse strategy is executed: The constant state object of the slow variable object is acquired. The constant state object is invoked to create a new drawable object instance. The new drawable object instance is subjected to a standard state independence process, which specifically comprises invoking at least one state independence process. The drawable object instance subjected to the standard state independence process is returned.

[0034] When the system needs to reuse a cached slow variable resource, the constant state object is also acquired as a prototype, and a new drawable object instance is created based on the prototype. The key difference lies in the subsequent purification process, which is subjected to a standard state independence process. The core of the process is to invoke a state independence process, which usually corresponds to directly invoking the variation method of the new instance in the technical practice of the Android system. This method generates an independent and modifiable state copy for the new instance, so that any subsequent state changes are limited to the new instance and do not affect other instances created from the same constant state object. After the process is completed, the new instance subjected to the standard isolation is returned for use.

[0035] More specifically, the following method is adopted when calculating its corresponding unique resource identifier: obtaining a binary data stream of the target resource; generating a unique hash value based on the MD5 information digest algorithm for the binary data stream, and taking the hash value as the unique resource identifier of the target resource.

[0036] First, the complete and original binary data stream of the resource is obtained, and then the entire binary data stream is fed as input to the MD5 information digest algorithm processor. The algorithm will perform complex mathematical and bit operations on the data stream, and finally generate a fixed-length hash value with high uniqueness. The hash value is adopted as the unique resource identifier of the target resource, which fundamentally solves the ambiguity and uncertainty problems caused by traditional file name or path identification.

[0037] More specifically, when the number of entries in the global resource cache pool reaches a preset threshold, the least recently used algorithm is used to remove resource objects in the cache pool.

[0038] Whenever a resource object in the cache pool is successfully accessed and reused, the system will immediately move it to the latest end of the access order record. When the total number of entries stored in the cache pool grows and reaches the preset upper threshold, the eviction mechanism is automatically triggered. At this time, the system accurately locates the resource object at the oldest end of the access order record, that is, the one that has not been accessed for the longest time, and removes it from the cache pool, releasing the occupied memory space, thereby creating space for the new resource to be stored.

[0039] As shown in Figure 2 , an Android runtime resource deduplication and reuse system includes the following: An interception module for intercepting target resource loading requests generated by program runtime through a hook mechanism; An identifier generation module connected to the interception module for calculating the unique resource identifier corresponding to the intercepted target resource loading request; A cache management module connected to the identifier generation module, the cache management module including a global resource cache pool; The global resource cache pool is a key-value pair set, where the key is the unique resource identifier and the value is the loaded resource; The cache management module is further configured to query the global resource cache pool based on the unique resource identifier, and if a matching loaded resource is found, the loaded resource is directly returned for reuse, and the original target resource loading process is terminated; The execution module, connected with the cache management module, is configured to invoke an original target resource loading process to create a new loaded resource when no matched loaded resource is found. The cache management module is further configured to store the new loaded resource and the unique resource identifier in the global resource cache pool in the form of a key-value pair after the resource loading execution module creates the new loaded resource.

[0040] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application, and they should be covered in the scope of the claims and the specification of the present application.

Claims

1. A method for deduplication and reuse of resources during Android runtime, characterized in that: The following steps are involved: Intercept the target resource loading request generated by the program during runtime through the hook mechanism; Calculate the unique resource identifier corresponding to the intercepted target resource; In a preset global resource cache pool, a query is performed based on the unique resource identifier; the global resource cache pool is a set of key-value pairs, wherein the key is the unique resource identifier and the value is the loaded resource; If a loaded resource matching the unique resource identifier is found in the global resource cache pool, resource classification is performed based on the constant state object of the loaded resource, and a reuse strategy is implemented according to the classification result, while terminating the original target resource loading process; If no loaded resource matching the unique resource identifier is found in the global resource cache pool, the target resource loading process is called to create a new loaded resource, and the new loaded resource and the unique resource identifier are stored in the global resource cache pool in the form of a key-value pair.

2. The method for deduplicating and reusing resources during Android runtime according to claim 1, wherein: When classifying resources based on the constant state object of the loaded resources, the following steps are specifically adopted: If the loaded resource is a resource for responding to an interactive state or a resource for responding to a value change, it is classified as a built-in state-type object; If the loaded resource does not belong to a built-in state type object, then obtaining a constant state object of the loaded resource, calling a variable process of the constant state object, and obtaining a value of a variable configuration identifier; If the value of the variable configuration flag is not zero, it is classified as a mutable object; If the value of the variable configuration flag is zero, it is classified as a stable object.

3. The method for deduplicating and reusing resources during Android runtime according to claim 2, wherein: When implementing a reuse strategy based on the classification results, if the cached resource is a built-in state-type object, the built-in state-type reuse strategy is executed: Obtain a constant state object of the built-in state type object; Calling the variable process of the constant state object to create a new drawable object instance; Returns the new drawable instance.

4. The method for deduplicating and reusing resources during Android runtime according to claim 2, wherein: When implementing a reuse strategy based on the classification results, if the cached resource is a stable object, the stable reuse strategy is executed: Searching a preset shared instance cache for a shared instance associated with the constant state object of the stable object; If the shared instance exists, the shared instance is directly returned as the reuse result; If the shared instance is not found, a new drawable object instance is created using the constant state object, the drawable object instance is stored as a new shared instance in the shared instance cache, and the new shared instance is returned.

5. The Android runtime resource deduplication and reuse method according to claim 2, characterized in that: If the value of the variable configuration flag is not zero, the classification as a variable object also includes the following classification steps: Using a lightweight convolution module to extract content feature data of the loaded resource to generate key features; Calculating the comparison distance between the key feature and a preset activity comparison feature set, and using a Softmax activation function to obtain an activity score based on the comparison distance; If the activity score is greater than a preset activity threshold, classifying the loaded resource as a highly variable object; If the activity score is less than a preset activity threshold, the loaded resource is classified as a slowly variable object.

6. The Android runtime resource deduplication and reuse method according to claim 5, characterized in that: When implementing a reuse strategy based on the classification results, if the cached resource is a highly mutable object, the highly mutable reuse strategy is executed: Obtaining a constant state object of the highly variable object; Calling the constant state object to create a new drawable object instance; Performing depth state independence processing on the new drawable object instance, wherein the depth state independence processing specifically comprises: sequentially calling at least two processes for achieving state independence, including at least one state independence process and one state reset process; Returns the drawable object instance after the depth state independence processing.

7. The Android runtime resource deduplication and reuse method according to claim 5, characterized in that: When implementing a reuse strategy based on the classification results, if the cached resource is a slowly mutating object, the slowly mutating reuse strategy is executed: Obtaining a constant state object of the slowly mutating variant object; Calling the constant state object to create a new drawable object instance; Performing standard state independence processing on the new drawable object instance, wherein the standard state independence processing specifically includes: calling at least one process for achieving state independence; Returns the drawable object instance after the standard state independence processing.

8. The Android runtime resource deduplication and reuse method according to claim 1, characterized in that: The corresponding unique resource identifier is calculated in the following way: Obtaining the binary data stream of the target resource; Based on the MD5 message digest algorithm, a unique hash value is generated for the binary data stream, and the hash value is used as the unique resource identifier of the target resource.

9. The Android runtime resource deduplication and reuse method according to claim 1, characterized in that: When the number of entries in the global resource cache pool reaches a preset threshold, the least recently used algorithm is used to remove resource objects in the cache pool.

10. An Android runtime resource deduplication and reuse system, characterized in that: Includes the following: The interception module is used to intercept the target resource loading request generated by the program during runtime through the hook mechanism; An identifier generation module, connected to the interception module, for calculating a corresponding unique resource identifier according to the intercepted target resource loading request; A cache management module, connected to the identifier generation module, the cache management module including a global resource cache pool; The global resource cache pool is a key-value pair set, wherein the key is the unique resource identifier and the value is the loaded resource; The cache management module is further configured to: query the global resource cache pool based on the unique resource identifier, and if a matching loaded resource is found, directly return the loaded resource for reuse and terminate the original target resource loading process; An execution module, connected to the cache management module, for calling the original target resource loading process to create a new loaded resource when no matching loaded resource is found; The cache management module is further configured to: after the resource loading execution module creates the new loaded resource, store the new loaded resource and the unique resource identifier in the global resource cache pool in the form of a key-value pair.

Citation Information

Patent Citations

  • Webpage display method and device, equipment, medium and product

    CN115292643A

  • Software resource processing method and device

    CN116166620A

Cited By

  • Layer rendering parameter configuration method and device and storage medium

    CN121934942A