Detailed Description
At present, various applications are applied to a mobile terminal, and due to the fact that a large number of services are rapidly on-line, starting performance of an application in a cold starting stage is not ideal, and use experience of a user is further influenced. In order to improve the use experience of the user on the application, the traditional optimization scheme can optimize the UI layout or optimize the code structure, so that the starting performance of the cold start of the application is improved, and the time required by the cold start of the application is reduced. However, this conventional optimization scheme is of little consequence, for example, it may only reduce the time required to apply a cold start by 10ms, and it may also consume a significant amount of time and effort from the developer.
In order to solve the above problems, the present specification considers from another point of view, and finds that applying a cold boot stage consumes a lot of time in a disk I/O (disk I/O, reading data of a certain sector from a disk or writing data into a certain sector of a disk by a command, the command generally notifies a beginning sector position of the disk, then gives a number of consecutive sectors that need to go back from the beginning sector, and simultaneously gives a corresponding operation of reading or writing, and the disk receives the command, and reads or writes data according to the command requirement, and one read or write data is a disk I/O), because applying the cold boot stage, there will be a lot of file read/write operations, and more real disk I/os will occur, if the number of times of these disk I/os can be reduced, the whole starting performance can be obviously improved, and the use experience of the whole application is further improved.
On a mobile terminal, for example, a bottom layer system of an Android system is a Linux system, a Linux file system has a Cache mechanism (Page Cache, Page Cache memory, Page Cache for short, and the size is usually 4K, and when a file is read and written, it is used for caching the logical content of the file, thereby accelerating access to an image and data on a disk), and when data is read from the disk each time, the Linux file system reads the data according to the size of 16 × 4K by default and puts the read data into a Cache, and if the data corresponding to the next read file is already in the Cache, real disk I/O does not occur, but the data is directly read from the Cache, which is compared with reading the data from the Cache, and it takes much time to read the data from the disk. If the file to be read next time is located behind the file to be read this time in the file arrangement layout, the file is placed into the cache with a high probability that the corresponding data is read from the disk at the same time when the file is read this time, so that one real disk I/O is reduced. For example, for A, B two files 1K each, if B is arranged behind a, when reading the a file, the read space of 16 × 4K reads the data corresponding to the B file and places the data corresponding to the B file in the buffer while reading the data corresponding to the a file from the disk, so that when reading the B file, real disk I/O does not occur, and the data corresponding to the B file is directly read from the buffer.
According to the thought, if the application cold start stage can be measured, the files required by the application cold start are arranged together by adjusting the file layout, and the actual disk I/O times can be effectively reduced by utilizing a cache mechanism. Because the files included in the general application are basically sorted according to the default a-z and 0-9 sequences, the files required in the cold start stage of the application may irregularly exist in the files included in the application, for example, the required files are file a, file B and file C, the sizes of which are 1K respectively, based on the initial file layout, the actual disk I/O occurs 3 times when the required files are loaded in the cold start of the application, if the file layout is adjusted, the file a, the file B and the file C are arranged together, and the actual disk I/O occurs 1 time when the required files are loaded in the cold start of the application, the number of times of the actual disk I/O is effectively reduced, the start performance of the application can be improved, and the time required by the cold start of the application is reduced.
Based on the above analysis, the embodiments of the present specification provide a technical solution for adjusting a file layout, where for an application to be optimized, a file identifier corresponding to a file required by the application during cold start is determined, a first file identifier list and a second file identifier list are determined, wherein the first file identification list and the second file identification list can be obtained according to the file identification corresponding to the file required by the application in cold start, the first file identification list and the second file identification list are integrated, according to the integration result, adjusting the current file layout corresponding to all files included in the application to be optimized, and subsequently, when the application is cold started next time, utilizing a cache mechanism based on the adjusted file layout, the method can effectively reduce the number of times of real disk I/O, improve the cold start performance of the application and reduce the time required by the cold start of the application. For the developer, the time and the energy consumed by the developer for optimizing the application source code can be saved because the optimization of the application source code is not involved.
Specifically, the technical solutions provided in the embodiments of the present specification are as follows:
determining an application to be optimized; for the application to be optimized, determining a file identifier corresponding to a file required by the application to be optimized during cold start; determining a first file identifier list and a second file identifier list, wherein the first file identifier list is as follows: the second file identifier list is composed of file identifiers corresponding to files required by the application to be optimized during cold start, and the file identifiers are as follows: the file identification corresponding to the rest files except the required file included in the application to be optimized is formed; integrating the first file identification list and the second file identification list; and adjusting the current file layout of all files included in the application to be optimized according to the integration result.
In order to make those skilled in the art better understand the technical solutions in the embodiments of the present specification, the technical solutions in the embodiments of the present specification will be described in detail below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all the embodiments. All other embodiments that can be derived by one of ordinary skill in the art from the embodiments given herein are intended to be within the scope of protection.
As shown in fig. 1, a schematic flow chart of a file layout adjustment method provided in an embodiment of the present specification may specifically include the following steps:
s101, determining an application to be optimized;
in this specification, a game application, a social application, a video playing application, an instant messaging application, a shopping application, and the like are installed on a mobile terminal at the same time, and when a cold start stage of a certain application needs to be optimized, the certain application may be manually specified, or the application to be optimized may be determined in an instruction form, that is, an instruction is manually input, where the instruction carries an identifier of the application, and when the instruction is received, the application to be optimized may be determined by the identifier carried in the instruction, for example, the application to be optimized is determined to be a pay treasure. There are many specific implementation manners for determining the application to be optimized, and the embodiments of this specification are not described herein any more.
S102, determining a file identifier corresponding to a file required by the application to be optimized during cold start for the application to be optimized;
and for the application to be optimized determined in the step S101, determining a file identifier corresponding to a file required by the application to be optimized during cold start. Specifically, there are various implementation manners for determining the file identifier corresponding to the file required by the application to be optimized during cold start, and this description exemplifies two implementation manners:
one implementation manner for determining the file identifier corresponding to the file required by the application to be optimized during cold start is as follows: and acquiring a file loading log generated when the application to be optimized is cold started based on the current file layout of all files included in the application to be optimized, and analyzing a loading record of a required file recorded in the file loading log to determine a file identifier corresponding to the required file when the application to be optimized is cold started. In order to conveniently determine the file identifier corresponding to the required file during the cold start of the application to be optimized, the file loading log is recorded while the required file is loaded at the loading stage of the cold start file of the application. When the application is in cold start based on the current file layout of all files, a file loading log is correspondingly generated, the file loading log generated when the application is in cold start is obtained, a loading record of a required file recorded in the file loading log is analyzed, the loading record at least comprises the loading time of the required file, the file name and size of the required file, a file directory, an application name and the like, the file name and size of the required file, namely the file identification of the required file can be obtained, and therefore the file identification corresponding to the required file when the application to be optimized is in cold start can be determined.
For example, for an application a including 10 files, the current 10 files are ordered in an order of a-z by default, based on the current file layout of the files, the file loading required by the application a in the cold start file loading stage is 4 files, the file loading log is generated by loading the file during the application a cold start, the loading record of the required file is analyzed from the file loading log, and the file names and sizes of the 4 files, such as a (1K), C (2K), D (1K), and F (2K), can be obtained from the loading record.
Another implementation manner for determining the file identifier corresponding to the file required by the application to be optimized during cold start is as follows: the method comprises the steps of obtaining a pre-compiled script, wherein the script is used for counting file behaviors when an application is in cold start, the file behaviors are whether a file has real disk I/O or not and whether the file hits a cache or not, the file with the disk I/O and the file with the cache hit is a file required when the application is in cold start, a file list and a file offset corresponding to the file required in the cold start stage of the application and whether the file has real disk I/O or the cache hit can be counted by using the script, a file identifier corresponding to each file can be obtained according to the file list, and the file identifier corresponding to the file required when the application to be optimized is in cold start can be determined.
For example, as shown in Table 1 below, the hit cache is 0 and a true disk I/O of 1 occurs.
TABLE 1
And obtaining the file identifier corresponding to the file required by the application to be optimized in cold start according to the file list. After determining the file identifiers corresponding to the files required by the application to be optimized in cold start, the current file layout can be adjusted according to the file identifiers.
S103, determining a first file identification list and a second file identification list, wherein the first file identification list is as follows: the second file identifier list is composed of file identifiers corresponding to files required by the application to be optimized during cold start, and the file identifiers are as follows: the file identification corresponding to the rest files except the required file included in the application to be optimized is formed;
for the file identifier corresponding to the file required by the application to be optimized in the cold start determined in S102, the first file identifier list and the second file identifier list may be determined according to the file identifiers.
And the first file identification list is composed of file identifications corresponding to the required files when the application to be optimized is in cold start, and the file identifications corresponding to the required files are sequenced. Preferably, the file identifiers corresponding to the required files may be sorted according to the loading time sequence of the required files when the application to be optimized is cold-started, so as to obtain a file identifier list.
For example, according to the loading time sequence of the required files when the application to be optimized is cold started, the file identifiers corresponding to the required files are sorted, so as to obtain a file identifier list, where the file identifier list may be: A. c, D, F, J, K, meaning that in the file load chronological order, the load chronological order of file A is ranked first, the load chronological order of file C is ranked second, and so on.
And a second file identifier list, which is composed of file identifiers corresponding to the remaining files, except the required file, included in the application to be optimized, and is obtained by sorting the file identifiers corresponding to the remaining files, except the required file, included in the application to be optimized according to an original default sorting rule, that is, by using an initial sorting rule, for example, by using an a-z and 0-9 default sorting rule, the file identifiers corresponding to the remaining files are still sorted according to an a-z and 0-9 default sorting rule to obtain the second file identifier list.
For example, the remaining files except the required file are ask B, file E, file G, file H, and file I, and the corresponding file identifiers are: B. e, G, H, I, the file identifiers corresponding to the remaining files are still sorted according to a-z and 0-9 default sorting rule to obtain a second file identifier list: B. e, G, H, I are provided.
S104, integrating the first file identification list and the second file identification list;
the first file identification list and the second file identification list are integrated to generate a third file identification list, the first file identification list can be specifically inserted into any position in the second file identification list to generate the third file identification list, namely, the first file identification list is regarded as a whole and inserted into any position such as the head, the tail and the middle of the second file identification list, and therefore a new file identification list can be generated.
For example, the first list of file identifications is: A. c, D, F, J, K, the second file identification list is: B. e, G, H, I, inserting the first file identification list into the second file identification list after B, the generated third file identification list is: B. a, C, D, F, J, K, E, G, H, I are provided.
S105, according to the integration result, adjusting the current file layout of all files included in the application to be optimized.
For the integration result obtained in S104, the current file layouts of all files included in the application to be optimized may be adjusted according to the integration result, that is, the arrangement order of all files included in the application to be optimized may be adjusted according to the integration result.
For example, according to the integration result, i.e., the third file identification list: B. a, C, D, F, J, K, E, G, H, I, adjusting the arrangement sequence of the file A, the file B, the file C, the file D, the file E, the file F, the file G, the file H, the file I, the file J and the file K included by the application, wherein the adjusted file layout is as follows: file B, file a, file C, file D, file F, file J, file K, file E, file G, file H, file I.
For applications on a mobile terminal, for example, files included in an application (for example, an Android system) on a mobile phone generally exist in a compressed form, for example, an APK (Android Package) file is actually in a Zip format, and in order to realize adjustment of file layout, a compression tool needs to be called by means of a compression tool, for example, a 7-Zip compression tool, so as to import a third file identifier list into the compression tool, execute a file compression function of the compression tool, and subsequently change the arrangement order of all files according to the third file identifier list, thereby achieving the purpose of adjusting the file layout.
Therefore, the files required by the application in cold start are arranged together, so that less real disk I/O can be generated, and the cold start performance is improved due to less real disk I/O generation based on the adjusted file layout when the subsequent application is subjected to the next cold start, thereby effectively reducing the time consumed by the cold start, wherein the effect pair is as shown in the following table 2:
TABLE 2
Through the above description of the technical solution provided in the embodiment of the present specification, for an application to be optimized, a file identifier corresponding to a file required by the application during cold start is determined, a first file identifier list and a second file identifier list are determined, the first file identifier list and the second file identifier list are integrated, a current file layout corresponding to all files included in the application to be optimized is adjusted according to an integration result, and then, when the application is cold started next time, based on the adjusted file layout, a cache mechanism is utilized, so that the number of times of real disk I/O can be effectively reduced, the cold start performance of the application is improved, and the time required by the cold start of the application is reduced. For the developer, the time and the energy consumed by the developer for optimizing the application source code can be saved because the optimization of the application source code is not involved.
With respect to the above method embodiment, an embodiment of the present specification further provides a file layout adjusting apparatus, and referring to fig. 2, the apparatus may include: an application determination module 210, a file identification determination module 220, an identification list determination module 230, an integration module 240, and a file layout adjustment module 250.
An application determination module 210 for determining an application to be optimized;
the file identifier determining module 220 is configured to determine, for the application to be optimized, a file identifier corresponding to a file required by the application to be optimized when the application to be optimized is cold started;
an identifier list determining module 230, configured to determine a first file identifier list and a second file identifier list, where the first file identifier list is: the second file identifier list is composed of file identifiers corresponding to files required by the application to be optimized during cold start, and the file identifiers are as follows: the file identification corresponding to the rest files except the required file included in the application to be optimized is formed;
an integration module 240, configured to integrate the first file identifier list and the second file identifier list;
and a file layout adjusting module 250, configured to adjust current file layouts of all files included in the application to be optimized according to the integration result.
According to a specific embodiment provided in this specification, the file identifier determining module 220 is specifically configured to:
acquiring a file loading log generated when the application to be optimized is cold started based on the current file layout of all files included in the application to be optimized;
and analyzing the loading record of the required file recorded in the file loading log to determine the file identifier corresponding to the required file when the application to be optimized is in cold start.
According to an embodiment provided by the present specification, the integration module 240 is specifically configured to:
and inserting the first file identification list into any position in the second file identification list.
According to one embodiment provided in the present specification,
the first file identification list is: and sequencing the file identifications corresponding to the required files according to the loading time sequence of the required files when the application to be optimized is in cold start.
According to one embodiment provided in the present specification,
the second file identification list is: and sequencing the file identifications corresponding to the rest files except the required file included in the application to be optimized according to the original default sequencing rule.
The implementation process of the functions and actions of each module in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
Through the above description of the technical solution provided in the embodiment of the present specification, for an application to be optimized, a file identifier corresponding to a file required by the application during cold start is determined, a first file identifier list and a second file identifier list are determined, the first file identifier list and the second file identifier list are integrated, a current file layout corresponding to all files included in the application to be optimized is adjusted according to an integration result, and then, when the application is cold started next time, based on the adjusted file layout, a cache mechanism is utilized, so that the number of times of real disk I/O can be effectively reduced, the cold start performance of the application is improved, and the time required by the cold start of the application is reduced. For the developer, the time and the energy consumed by the developer for optimizing the application source code can be saved because the optimization of the application source code is not involved.
Embodiments of the present specification further provide a computer device, as shown in fig. 3, the computer device may include: a processor 310, a memory 320, an input/output interface 330, a communication interface 340, and a bus 350. Wherein the processor 310, memory 320, input/output interface 330, and communication interface 340 are communicatively coupled to each other within the device via bus 350.
The processor 310 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits, and is configured to execute related programs to implement the technical solutions provided in the embodiments of the present specification.
The Memory 320 may be implemented in the form of a ROM (Read Only Memory), a RAM (Random Access Memory), a static storage device, a dynamic storage device, or the like. The memory 320 may store an operating system and other application programs, and when the technical solution provided by the embodiments of the present specification is implemented by software or firmware, the relevant program codes are stored in the memory 320 and called to be executed by the processor 310.
The input/output interface 330 is used for connecting an input/output module to realize information input and output. The i/o module may be configured as a component in a device (not shown) or may be external to the device to provide a corresponding function. The input devices may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output devices may include a display, a speaker, a vibrator, an indicator light, etc.
The communication interface 340 is used for connecting a communication module (not shown in the figure) to implement communication interaction between the present device and other devices. The communication module can realize communication in a wired mode (such as USB, network cable and the like) and also can realize communication in a wireless mode (such as mobile network, WIFI, Bluetooth and the like).
Bus 350 includes a path that transfers information between the various components of the device, such as processor 310, memory 320, input/output interface 330, and communication interface 340.
It should be noted that although the above-mentioned device only shows the processor 310, the memory 320, the input/output interface 330, the communication interface 340 and the bus 350, in a specific implementation, the device may also include other components necessary for normal operation. In addition, those skilled in the art will appreciate that the above-described apparatus may also include only those components necessary to implement the embodiments of the present description, and not necessarily all of the components shown in the figures.
Embodiments of the present specification also provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements the foregoing file layout adjustment method. The method at least comprises the following steps:
a method of adjusting a layout of a file, the method comprising:
determining an application to be optimized;
for the application to be optimized, determining a file identifier corresponding to a file required by the application to be optimized during cold start;
determining a first file identifier list and a second file identifier list, wherein the first file identifier list is as follows: the second file identifier list is composed of file identifiers corresponding to files required by the application to be optimized during cold start, and the file identifiers are as follows: the file identification corresponding to the rest files except the required file included in the application to be optimized is formed;
integrating the first file identification list and the second file identification list;
and adjusting the current file layout of all files included in the application to be optimized according to the integration result.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
From the above description of the embodiments, it is clear to those skilled in the art that the embodiments of the present disclosure can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the embodiments of the present specification may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments of the present specification.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to some descriptions of the method embodiment for relevant points. The above-described apparatus embodiments are merely illustrative, and the modules described as separate components may or may not be physically separate, and the functions of the modules may be implemented in one or more software and/or hardware when implementing the embodiments of the present disclosure. And part or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing is only a specific embodiment of the embodiments of the present disclosure, and it should be noted that, for those skilled in the art, a plurality of modifications and decorations can be made without departing from the principle of the embodiments of the present disclosure, and these modifications and decorations should also be regarded as the protection scope of the embodiments of the present disclosure.