@@ -30,52 +30,54 @@ impl easy::Handle {
30
30
/// the cache efficiency is low. Use `GITOXIDE_PACK_CACHE_MEMORY=512MB` to use up to 512MB of RAM for the pack delta base
31
31
/// cache. If none of these are set, the default cache is fast enough to nearly never cause a (marginal) slow-down while providing
32
32
/// some gains most of the time. Note that the value given is _per-thread_.
33
+ ///
34
+ /// Use the `GITOXIDE_OBJECT_CACHE_MEMORY=16mb` to set the given amount of memory to store full objects, on a per-thread basis.
33
35
pub fn apply_environment ( self ) -> Self {
34
36
// We have no cache types available without this flag currently. Maybe this should change at some point.
35
37
#[ cfg( not( feature = "max-performance" ) ) ]
36
38
return self ;
37
39
#[ cfg( feature = "max-performance" ) ]
38
40
{
39
- let new_pack_cache = {
40
- let pack_cache_disabled = std:: env:: var_os ( "GITOXIDE_DISABLE_PACK_CACHE" ) . is_some ( ) ;
41
- let bytes = ( !pack_cache_disabled)
42
- . then ( || {
43
- std:: env:: var ( "GITOXIDE_PACK_CACHE_MEMORY" )
44
- . ok ( )
45
- . and_then ( |v| {
46
- byte_unit:: Byte :: from_str ( & v)
47
- . map_err ( |err| {
48
- log:: warn!( "Failed to parse {:?} into byte unit for pack cache: {}" , v, err)
49
- } )
50
- . ok ( )
51
- } )
52
- . and_then ( |unit| {
53
- use std:: convert:: TryInto ;
54
- unit. get_bytes ( )
55
- . try_into ( )
56
- . map_err ( |err| {
57
- log:: warn!(
58
- "Parsed bytes value is not representable as usize. Defaulting to standard pack cache: {}" ,
59
- err
60
- )
61
- } )
62
- . ok ( )
63
- } )
64
- } )
65
- . flatten ( ) ;
66
- move || -> Box < git_odb:: handle:: PackCache > {
67
- if pack_cache_disabled {
68
- Box :: new ( git_pack:: cache:: Never )
69
- } else if let Some ( bytes) = bytes {
70
- Box :: new ( git_pack:: cache:: lru:: MemoryCappedHashmap :: new ( bytes) )
71
- } else {
72
- Box :: new ( git_pack:: cache:: lru:: StaticLinkedList :: < 64 > :: default ( ) )
73
- }
74
- }
75
- } ;
41
+ let pack_cache_disabled = std:: env:: var_os ( "GITOXIDE_DISABLE_PACK_CACHE" ) . is_some ( ) ;
76
42
let mut this = self ;
77
- this. objects . set_pack_cache ( new_pack_cache) ;
43
+ if !pack_cache_disabled {
44
+ let bytes = parse_bytes_from_var ( "GITOXIDE_PACK_CACHE_MEMORY" ) ;
45
+ let new_pack_cache = move || -> Box < git_odb:: handle:: PackCache > {
46
+ match bytes {
47
+ Some ( bytes) => Box :: new ( git_pack:: cache:: lru:: MemoryCappedHashmap :: new ( bytes) ) ,
48
+ None => Box :: new ( git_pack:: cache:: lru:: StaticLinkedList :: < 64 > :: default ( ) ) ,
49
+ }
50
+ } ;
51
+ this. objects . set_pack_cache ( new_pack_cache) ;
52
+ }
53
+ if let Some ( bytes) = parse_bytes_from_var ( "GITOXIDE_OBJECT_CACHE_MEMORY" ) {
54
+ this. objects
55
+ . set_object_cache ( move || Box :: new ( git_pack:: cache:: object:: MemoryCappedHashmap :: new ( bytes) ) ) ;
56
+ }
78
57
this
79
58
}
80
59
}
81
60
}
61
+
62
+ #[ cfg( feature = "max-performance" ) ]
63
+ fn parse_bytes_from_var ( name : & str ) -> Option < usize > {
64
+ std:: env:: var ( name)
65
+ . ok ( )
66
+ . and_then ( |v| {
67
+ byte_unit:: Byte :: from_str ( & v)
68
+ . map_err ( |err| log:: warn!( "Failed to parse {:?} into byte unit for pack cache: {}" , v, err) )
69
+ . ok ( )
70
+ } )
71
+ . and_then ( |unit| {
72
+ use std:: convert:: TryInto ;
73
+ unit. get_bytes ( )
74
+ . try_into ( )
75
+ . map_err ( |err| {
76
+ log:: warn!(
77
+ "Parsed bytes value is not representable as usize. Defaulting to standard pack cache: {}" ,
78
+ err
79
+ )
80
+ } )
81
+ . ok ( )
82
+ } )
83
+ }
0 commit comments