public static StatisticsUpdate collectStatisticChanges(LookupElement item, final Lookup lookup) {
    applyLastCompletionStatisticsUpdate();

    final StatisticsInfo base = StatisticsWeigher.getBaseStatisticsInfo(item, null);
    if (base == StatisticsInfo.EMPTY) {
      return new StatisticsUpdate(StatisticsInfo.EMPTY);
    }

    StatisticsUpdate update =
        new StatisticsUpdate(
            StatisticsWeigher.composeStatsWithPrefix(base, lookup.itemPattern(item), true));
    ourPendingUpdate = update;
    Disposer.register(
        update,
        new Disposable() {
          @Override
          public void dispose() {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            ourPendingUpdate = null;
          }
        });

    return update;
  }
  @Override
  public void addElement(
      Lookup lookup, LookupElement element, LookupElementPresentation presentation) {
    StatisticsWeigher.clearBaseStatisticsInfo(element);

    final String invariant =
        presentation.getItemText()
            + "###"
            + getTailTextOrSpace(presentation)
            + "###"
            + presentation.getTypeText();
    element.putUserData(PRESENTATION_INVARIANT, invariant);

    CompletionSorterImpl sorter = obtainSorter(element);
    Classifier<LookupElement> classifier = myClassifiers.get(sorter);
    if (classifier == null) {
      myClassifiers.put(sorter, classifier = sorter.buildClassifier(new AlphaClassifier(lookup)));
    }
    classifier.addElement(element);

    super.addElement(lookup, element, presentation);
  }