Repository: vespa-engine/vespa
File: config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java (Java)

Code before:
        ContainerDocproc containerDocproc = buildDocproc(deployState, cluster, spec);
        if (containerDocproc == null) return;
        cluster.setDocproc(containerDocproc);

        ContainerDocproc.Options docprocOptions = containerDocproc.options;
        cluster.setMbusParams(new ApplicationContainerCluster.MbusParams(
                docprocOptions.maxConcurrentFactor, docprocOptions.documentExpansionFactor, docprocOptions.containerCoreMemory));
    }

    private void addSearch(DeployState deployState, Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) {
        Element searchElement = XML.getChild(spec, "search");
        if (searchElement == null) return;

        addIncludes(searchElement);
        cluster.setSearch(buildSearch(deployState, cluster, searchElement));

        addSearchHandler(deployState, cluster, searchElement, context);

        validateAndAddConfiguredComponents(deployState, cluster, searchElement, "renderer", ContainerModelBuilder::validateRendererElement);

        addSignificance(deployState, searchElement, cluster);
    }

    private void addDefaultThreadpool(DeployState deployState, Element spec, ApplicationContainerCluster cluster) {
        Element threadpoolElement = XML.getChild(spec, "threadpool");
        if (threadpoolElement == null) return;
        var options = ContainerThreadpoolOptionsBuilder.build(deployState, spec);
        cluster.setDefaultThreadpoolProvider(new DefaultThreadpoolProvider(deployState, cluster, options));
    }

    private void addSignificance(DeployState deployState, Element spec, ApplicationContainerCluster cluster) {
        Element significanceElement = XML.getChild(spec, "significance");

        SignificanceModelRegistry significanceModelRegistry = new SignificanceModelRegistry(deployState, significanceElement);
        cluster.addComponent(significanceModelRegistry);

    }

    private void addModelEvaluation(Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) {
        Element modelEvaluationElement = XML.getChild(spec, "model-evaluation");
        if (modelEvaluationElement == null) return;

        RankProfileList profiles =
                context.vespaModel() != null ? context.vespaModel().rankProfileList() : RankProfileList.empty;

        // Create a copy of models so each cluster can have its own specific settings
        FileDistributedOnnxModels models = profiles.getOnnxModels().clone();

        Element onnxElement = XML.getChild(modelEvaluationElement, "onnx");
        Element modelsElement = XML.getChild(onnxElement, "models");
        for (Element modelElement : XML.getChildren(modelsElement, "model") ) {

Review comment (suggestion):
Consider initializing and setting the default configuration of the provider when the XML element is not present. This removes the need for setting up the default instance on `ContainerCluster` constructor and the need for removing that component in `setDefaultThreadpoolProvider`

Code after:
        ContainerDocproc containerDocproc = buildDocproc(deployState, cluster, spec);
        if (containerDocproc == null) return;
        cluster.setDocproc(containerDocproc);

        ContainerDocproc.Options docprocOptions = containerDocproc.options;
        cluster.setMbusParams(new ApplicationContainerCluster.MbusParams(
                docprocOptions.maxConcurrentFactor, docprocOptions.documentExpansionFactor, docprocOptions.containerCoreMemory));
    }

    private void addSearch(DeployState deployState, Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) {
        Element searchElement = XML.getChild(spec, "search");
        if (searchElement == null) return;

        addIncludes(searchElement);
        cluster.setSearch(buildSearch(deployState, cluster, searchElement));

        addSearchHandler(deployState, cluster, searchElement, context);

        validateAndAddConfiguredComponents(deployState, cluster, searchElement, "renderer", ContainerModelBuilder::validateRendererElement);

        addSignificance(deployState, searchElement, cluster);
    }

    private void addDefaultThreadpool(DeployState deployState, Element spec, ApplicationContainerCluster cluster) {
        Element threadpoolElement = XML.getChild(spec, "threadpool");
        if (threadpoolElement == null) {
            cluster.setDefaultThreadpoolProvider(new DefaultThreadpoolProvider(cluster));
        } else {
            var options = ContainerThreadpoolOptionsBuilder.build(deployState, spec);
            cluster.setDefaultThreadpoolProvider(new DefaultThreadpoolProvider(deployState, cluster, options));
        }
    }

    private void addSignificance(DeployState deployState, Element spec, ApplicationContainerCluster cluster) {
        Element significanceElement = XML.getChild(spec, "significance");

        SignificanceModelRegistry significanceModelRegistry = new SignificanceModelRegistry(deployState, significanceElement);
        cluster.addComponent(significanceModelRegistry);

    }

    private void addModelEvaluation(Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) {
        Element modelEvaluationElement = XML.getChild(spec, "model-evaluation");
        if (modelEvaluationElement == null) return;

        RankProfileList profiles =
                context.vespaModel() != null ? context.vespaModel().rankProfileList() : RankProfileList.empty;

        // Create a copy of models so each cluster can have its own specific settings
        FileDistributedOnnxModels models = profiles.getOnnxModels().clone();