You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2022/07/18 13:04:19 UTC

[sling-org-apache-sling-feature-launcher] branch issue/SLING-11462 created (now 54c336b)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to branch issue/SLING-11462
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git


      at 54c336b  SLING-11462 - Reduce memory requirements if feature archives are not used

This branch includes the following new commits:

     new 54c336b  SLING-11462 - Reduce memory requirements if feature archives are not used

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-feature-launcher] 01/01: SLING-11462 - Reduce memory requirements if feature archives are not used

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch issue/SLING-11462
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git

commit 54c336b9b7b46847a3757ca79cc4ca4a7a137a50
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Jul 18 16:03:55 2022 +0300

    SLING-11462 - Reduce memory requirements if feature archives are not used
    
    Lazily initialise the buffer used for reading feature model archives.
---
 .../org/apache/sling/feature/launcher/impl/FeatureProcessor.java    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
index 379b0e6..763a186 100644
--- a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
+++ b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
@@ -108,16 +108,20 @@ public class FeatureProcessor {
         }
 
         List<Feature> features = new ArrayList<>();
-        final byte[] buffer = new byte[1024*1024*256];
+        // lazily initialised, we don't want to allocate that much memory unless needed
+        final byte[][] bufferHolder = new byte[1][];
         for (final String featureFile : config.getFeatureFiles()) {
             for (final String initFile : IOUtils.getFeatureFiles(config.getHomeDirectory(), featureFile)) {
                 if ( initFile.endsWith(IOUtils.EXTENSION_FEATURE_ARCHIVE) ) {
+                    if ( bufferHolder[0] == null )
+                        bufferHolder[0] = new byte[1024*1024*256];
                     logger.debug("Reading feature archive {}", initFile);
                     final ArtifactHandler featureArtifact = artifactManager.getArtifactHandler(initFile);
                     try (final InputStream is = featureArtifact.getLocalURL().openStream()) {
                         for(final Feature feature : ArchiveReader.read(is, (id, stream) -> {
                                 final File artifactFile = new File(config.getCacheDirectory(),
                                             id.toMvnPath().replace('/', File.separatorChar));
+                                byte[] buffer = bufferHolder[0];
                                 if (!artifactFile.exists()) {
                                     artifactFile.getParentFile().mkdirs();
                                     try (final OutputStream os = new FileOutputStream(artifactFile)) {