Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

plumbing: cache, enforce the use of cache in packfile decoder #698

Merged
merged 4 commits into from
Dec 20, 2017

Conversation

jfontan
Copy link
Contributor

@jfontan jfontan commented Dec 20, 2017

Decoder object can make use of an object cache to speed up processing.
Previously the only way to specify it was changing manually the struct
generated by NewDecodeForFile. This lead to some instances to be created
without it and penalized performance.

Now the cache should be explicitly passed to the constructor function.
NewDecoder now creates objects with a cache using the default size.

A new helper function was added to create cache objects with the default
size as this becomes a common task now:

cache.NewObjectLRUDefault()

Decoder object can make use of an object cache to speed up processing.
Previously the only way to specify it was changing manually the struct
generated by NewDecodeForFile. This lead to some instances to be created
without it and penalized performance.

Now the cache should be explicitly passed to the constructor function.
NewDecoder now creates objects with a cache using the default size.

A new helper function was added to create cache objects with the default
size as this becomes a common task now:

    cache.NewObjectLRUDefault()

Signed-off-by: Javi Fontan <[email protected]>
// deserialization of all the objects
// deserialization of all the objects.
//
// cacheObject is an ObjectLRU that is used to speed up the process. If cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache instance can be any implementation of cache.Object

//
// cacheObject is an ObjectLRU that is used to speed up the process. If cache
// is not needed you can pass nil. To create a cache object with the default
// size you an use the helper cache.ObjectLRUDefault().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/can/

o: o,
s: s,
o: o,
DeltaBaseCache: cacheObject,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make DeltaBaseCache private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed these issues in the following commits.

@@ -24,6 +24,11 @@ func NewObjectLRU(maxSize FileSize) *ObjectLRU {
return &ObjectLRU{MaxSize: maxSize}
}

// NewObjectLRUDefault creates a new ObjectLRU with the default cache size.
func NewObjectLRUDefault() *ObjectLRU {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no tested function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now cache tests are done twice. One with the previous cache and another time with a cache created with NewObjectLRUDefault.

@mcuadros mcuadros changed the title Enforce the use of cache in packfile decoder plumbing: cache, enforce the use of cache in packfile decoder Dec 20, 2017
@mcuadros mcuadros merged commit 5072513 into src-d:master Dec 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants