Skip to content

Commit

Permalink
Merge pull request #357 from sisong/dev
Browse files Browse the repository at this point in the history
diffFile created by xdelta3,open-vcdiff, always patch in mem; + xcode iOS's static lib
  • Loading branch information
sisong committed Aug 26, 2023
2 parents 4ab860a + bc1d59a commit fd75602
Show file tree
Hide file tree
Showing 18 changed files with 979 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ else
endif
ifeq ($(ARM64ASM),0)
else
DEF_FLAGS += -D_LZMA_DEC_OPT
DEF_FLAGS += -DZ7_LZMA_DEC_OPT
endif
endif
ifeq ($(ZSTD),0)
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [HDiffPatch](https://github.com/sisong/HDiffPatch)
[![release](https://img.shields.io/badge/release-v4.6.5-blue.svg)](https://github.com/sisong/HDiffPatch/releases)
[![release](https://img.shields.io/badge/release-v4.6.6-blue.svg)](https://github.com/sisong/HDiffPatch/releases)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HDiffPatch/blob/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HDiffPatch/pulls)
[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HDiffPatch?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/HDiffPatch/issues)
Expand Down Expand Up @@ -27,7 +27,7 @@ NOTE: *This library does not deal with file metadata, such as file last wirte ti
( release files build by projects in path `HDiffPatch/builds` )
use cmdline to create a delta:
`$hdiffz -m-6 -SD -c-zstd-21-24 -d oldPath newPath outDiffFile`
if file'size is very large, try changing `-m-6` to `-s-64`
if file is very large, try changing `-m-6` to `-s-64`
apply the delta:
`$hpatchz oldPath diffFile outNewPath`

Expand Down Expand Up @@ -206,10 +206,10 @@ memory options:
requires (cacheSize + 4*decompress buffer size)+O(1) bytes of memory.
if diffFile is single compressed diffData(created by hdiffz -SD-stepSize), then requires
(cacheSize+ stepSize + 1*decompress buffer size)+O(1) bytes of memory;
if diffFile is created by hdiffz -BSD,bsdiff4, hdiffz -VCD,xdelta3,open-vcdiff, then requires
if diffFile is created by hdiffz -BSD,bsdiff4, hdiffz -VCD, then requires
(cacheSize + 3*decompress buffer size)+O(1) bytes of memory;
if diffFile is VCDIFF: if created by hdiffz -VCD, then recommended patch by -s;
if created by xdelta3,open-vcdiff, then recommended patch by -m.
if diffFile is created by xdelta3,open-vcdiff, then requires
(sourceWindowSize+targetWindowSize + 3*decompress buffer size)+O(1) bytes of memory.
-m oldPath all loaded into Memory;
requires (oldFileSize + 4*decompress buffer size)+O(1) bytes of memory.
if diffFile is single compressed diffData(created by hdiffz -SD-stepSize), then requires
Expand Down Expand Up @@ -446,11 +446,11 @@ case list:
**sfpatcher -1 zstd** v1.1.1 diff with `-o-1 -c-zstd-21-23 -m-1 -step-3m -lp-512k -p-8 -cache -d {old} {new} {pat}`
**sfpatcher -2 lzma2** diff with `-o-2 -c-lzma2-9-4m -m-1 -step-2m -lp-8m -p-8 -cache -d {old} {new} {pat}`
sfpatcher patch with `-lp -p-8 {old} {pat} {new}`
adding test hpatchz&hsynz&sfpatcher on Android, CPU Kirin 980(2×A76 2.6G + 2×A76 1.92G + 4×A55 1.8G)
adding test hpatchz&hsynz&sfpatcher on Android, CPU Kirin980(2×A76 2.6G + 2×A76 1.92G + 4×A55 1.8G)
( [archive-patcher](https://github.com/google/archive-patcher), [sfpatcher](https://github.com/sisong/sfpatcher) optimized diff&patch between apk files )

**test result average**:
|Program|compress|diff mem|speed|patch mem|max mem|speed|Kirin 980|
|Program|compress|diff mem|speed|patch mem|max mem|speed|arm Kirin980|
|:----|----:|----:|----:|----:|----:|----:|----:|
|zstd --patch-from|53.18%|2199M|3.6MB/s|209M|596M|609MB/s|
|xdelta3|54.51%|422M|3.8MB/s|98M|99M|170MB/s|
Expand Down
2 changes: 1 addition & 1 deletion builds/android_ndk_jni_mk/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ifeq ($(LZMA),0)
else
DEF_FLAGS += -D_CompressPlugin_lzma -D_CompressPlugin_lzma2 -DZ7_ST -I$(LZMA_PATH)
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
DEF_FLAGS += -D_LZMA_DEC_OPT
DEF_FLAGS += -DZ7_LZMA_DEC_OPT
endif
ifeq ($(VCD),0)
else
Expand Down
2 changes: 1 addition & 1 deletion builds/android_ndk_jni_mk/hpatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ void bz_internal_error(int errcode){
int hpatchz(const char *oldFileName,const char *diffFileName,
const char *outNewFileName, size_t cacheMemory){
return hpatch(oldFileName,diffFileName,outNewFileName,
hpatch_FALSE,cacheMemory,0,0,1);
hpatch_FALSE,cacheMemory,0,0,1,1);
}
11 changes: 8 additions & 3 deletions builds/android_ndk_jni_mk/hpatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
#ifdef __cplusplus
extern "C" {
#endif
#define H_PATCH_EXPORT __attribute__((visibility("default")))

#ifndef H_PATCH_EXPORT
# if ( __GNUC__ >= 4 )
#define H_PATCH_EXPORT __attribute__((visibility("default")))
# else
#define H_PATCH_EXPORT
# endif
#endif

// return THPatchResult, 0 is ok
// 'diffFileName' file is create by hdiffz app,or by create_compressed_diff(),create_compressed_diff_stream()
int hpatchz(const char *oldFileName,const char *diffFileName,
const char *outNewFileName, size_t cacheMemory) H_PATCH_EXPORT;

Expand Down
24 changes: 11 additions & 13 deletions builds/android_ndk_jni_mk/java/com/github/sisong/HPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ public class HPatch{
// auto load libhpatchz.so ?
// static { System.loadLibrary("hpatchz"); }

// return THPatchResult, 0 is ok
// different cacheMemory only affects patch speed, if cacheMemory<0 then default 256*1024;
// if diffFile created by hdiffz,hdiffz -SD,hdiffz -VCD,bsdiff4,hdiffz -BSD,
// then cacheMemory recommended 256*1024,1024*1024,...
// if diffFile created by xdelta3(-S,-S lzma),open-vcdiff, and patch very slow,
// then cacheMemory recommended sourceWindowSize+targetWindowSize+256*1024;
// ( window sizes is set when diff, C API getVcDiffInfo() can got values. )
// if diffFile created by bsdiff4, and patch very slow,
// then cacheMemory recommended oldFileSize+256*1024;
public static native int patch(String oldFileName,String diffFileName,
String outNewFileName,long cacheMemory);

public static int patch(String oldFileName,String diffFileName,String outNewFileName){
//patch:
// return THPatchResult, 0 is ok
// cacheMemory:
// cacheMemory is used for file IO, different cacheMemory only affects patch speed;
// recommended 256*1024,1024*1024,... if cacheMemory<0 then default 256*1024;
// NOTE: if diffFile created by $xdelta3(-S,-S lzma),$open-vcdiff, alloc memory+=sourceWindowSize+targetWindowSize;
// ( sourceWindowSize & targetWindowSize is set when diff, C API getVcDiffInfo() can got values from diffFile. )
// if diffFile created by $bsdiff4, and patch very slow,
// then cacheMemory recommended oldFileSize+256*1024;
public static native int patch(String oldFileName,String diffFileName,String outNewFileName,long cacheMemory);
public static final int patch(String oldFileName,String diffFileName,String outNewFileName){
return patch(oldFileName,diffFileName,outNewFileName,-1);
}
}
2 changes: 1 addition & 1 deletion builds/vc/lzma.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;_LZMA_DEC_OPT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;Z7_LZMA_DEC_OPT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeaderFile>
Expand Down
8 changes: 4 additions & 4 deletions builds/xcode/hdiffz.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0D571A64275CEB3B00672D57 /* liblzma.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D571A63275CEB3B00672D57 /* liblzma.a */; };
0D225ADB2A997B6200DBD5B1 /* liblzma.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D225ADA2A997B6200DBD5B1 /* liblzma.a */; };
0D571A66275CEB3B00672D57 /* libzstd.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D571A65275CEB3B00672D57 /* libzstd.a */; };
0D571A69275CF68900672D57 /* match_block.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0D571A68275CF68900672D57 /* match_block.cpp */; };
0D571A6F275CF71A00672D57 /* bspatch_wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 0D571A6B275CF71A00672D57 /* bspatch_wrapper.c */; };
Expand Down Expand Up @@ -57,7 +57,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0D571A63275CEB3B00672D57 /* liblzma.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = liblzma.a; sourceTree = BUILT_PRODUCTS_DIR; };
0D225ADA2A997B6200DBD5B1 /* liblzma.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = liblzma.a; sourceTree = BUILT_PRODUCTS_DIR; };
0D571A65275CEB3B00672D57 /* libzstd.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libzstd.a; sourceTree = BUILT_PRODUCTS_DIR; };
0D571A68275CF68900672D57 /* match_block.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = match_block.cpp; sourceTree = "<group>"; };
0D571A6B275CF71A00672D57 /* bspatch_wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = bspatch_wrapper.c; path = ../../bsdiff_wrapper/bspatch_wrapper.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,8 +155,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0D225ADB2A997B6200DBD5B1 /* liblzma.a in Frameworks */,
0D571A66275CEB3B00672D57 /* libzstd.a in Frameworks */,
0D571A64275CEB3B00672D57 /* liblzma.a in Frameworks */,
D690AEFD1F2097D30089DC57 /* libz.tbd in Frameworks */,
D690AEFB1F2097C90089DC57 /* libbz2.tbd in Frameworks */,
);
Expand Down Expand Up @@ -351,7 +351,7 @@
D690ABBD1F20832E0089DC57 /* Frameworks */ = {
isa = PBXGroup;
children = (
0D571A63275CEB3B00672D57 /* liblzma.a */,
0D225ADA2A997B6200DBD5B1 /* liblzma.a */,
0D571A65275CEB3B00672D57 /* libzstd.a */,
D690AEFC1F2097D30089DC57 /* libz.tbd */,
D690AEFA1F2097C90089DC57 /* libbz2.tbd */,
Expand Down
21 changes: 17 additions & 4 deletions builds/xcode/hpatchz.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
0D225B1A2A99893300DBD5B1 /* liblzma.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D225B192A99893300DBD5B1 /* liblzma.a */; };
0D571A5C275CE9CE00672D57 /* libzstd.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D571A5B275CE9CE00672D57 /* libzstd.a */; };
0D571A5D275CE9CE00672D57 /* liblzma.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D64B4BFE2077B9240039C38B /* liblzma.a */; };
0D571A62275CEAE900672D57 /* bspatch_wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 0D571A61275CEAE900672D57 /* bspatch_wrapper.c */; };
0DA2A8E52910E70D000E86E1 /* vcpatch_wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 0DA2A8E42910E70D000E86E1 /* vcpatch_wrapper.c */; };
D6241AE521DE47EC00E2846A /* new_stream.c in Sources */ = {isa = PBXBuildFile; fileRef = D6241AE321DE47EC00E2846A /* new_stream.c */; };
Expand Down Expand Up @@ -38,6 +38,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0D225B192A99893300DBD5B1 /* liblzma.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = liblzma.a; sourceTree = BUILT_PRODUCTS_DIR; };
0D571A5B275CE9CE00672D57 /* libzstd.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libzstd.a; sourceTree = BUILT_PRODUCTS_DIR; };
0D571A61275CEAE900672D57 /* bspatch_wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = bspatch_wrapper.c; path = ../../bsdiff_wrapper/bspatch_wrapper.c; sourceTree = "<group>"; };
0DA2A8E42910E70D000E86E1 /* vcpatch_wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vcpatch_wrapper.c; path = ../../vcdiff_wrapper/vcpatch_wrapper.c; sourceTree = "<group>"; };
Expand All @@ -52,7 +53,6 @@
D64B4BF42077AB550039C38B /* file_for_patch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = file_for_patch.h; path = ../../file_for_patch.h; sourceTree = "<group>"; };
D64B4BF82077B9090039C38B /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
D64B4BFA2077B91A0039C38B /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; };
D64B4BFE2077B9240039C38B /* liblzma.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = liblzma.a; sourceTree = BUILT_PRODUCTS_DIR; };
D6553CB3165FA1A9009D4C44 /* hpatchz */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = hpatchz; sourceTree = BUILT_PRODUCTS_DIR; };
D67D3BF021D3C5870050632A /* dir_patch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dir_patch.h; sourceTree = "<group>"; };
D67D3BF121D3C5870050632A /* ref_stream.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ref_stream.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,7 +81,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0D571A5D275CE9CE00672D57 /* liblzma.a in Frameworks */,
0D225B1A2A99893300DBD5B1 /* liblzma.a in Frameworks */,
0D571A5C275CE9CE00672D57 /* libzstd.a in Frameworks */,
D64B4BFB2077B91A0039C38B /* libbz2.tbd in Frameworks */,
D64B4BF92077B9090039C38B /* libz.tbd in Frameworks */,
Expand All @@ -94,8 +94,8 @@
D64B4BF72077B9090039C38B /* Frameworks */ = {
isa = PBXGroup;
children = (
0D225B192A99893300DBD5B1 /* liblzma.a */,
0D571A5B275CE9CE00672D57 /* libzstd.a */,
D64B4BFE2077B9240039C38B /* liblzma.a */,
D64B4BFA2077B91A0039C38B /* libbz2.tbd */,
D64B4BF82077B9090039C38B /* libz.tbd */,
);
Expand Down Expand Up @@ -203,6 +203,11 @@
attributes = {
LastUpgradeCheck = 1030;
ORGANIZATIONNAME = HouSisong;
TargetAttributes = {
D6553CB2165FA1A9009D4C44 = {
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = D6553CAE165FA1A9009D4C44 /* Build configuration list for PBXProject "hpatchz" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -353,17 +358,25 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
MACOSX_DEPLOYMENT_TARGET = 10.9;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
};
name = Debug;
};
D6553CBE165FA1A9009D4C44 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
MACOSX_DEPLOYMENT_TARGET = 10.9;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
};
name = Release;
};
Expand Down
Loading

0 comments on commit fd75602

Please sign in to comment.