Skip to main content
Participating Frequently
April 17, 2023
Question

After upgrading from SDK 13 to SDK 14, the retrieval operation became slower

  • April 17, 2023
  • 2 replies
  • 793 views

We implemented the retrieval function through the ITextwalker interface. After upgrading from SDK 13 to SDK 14, the performance of the retrieval operation deteriorated. However, it was not all the data, but only some data performed worse. The data that took more than 200 milliseconds in SDK 13 took more than 700 milliseconds in SDK 114. 

The following is our code implementation. Can anyone give me some advises? Thank you。

 

/** SearchText
  Search text in a story ITextWalker

*  @9397041 textStart    [in]    the start position of the text search range
*  @9397041 textLength    [in]    the length of the text search range
*  @9397041 searchText    [in]    text to be searched
*  @9397041 foundStartPos  [out]    the start position of the found text

*  @retval      kSuccess  success
*  @retval      kFailure  failure
*  @10397173
*/
ErrorCode TextModelHelper::SearchText(int32 textStart, int32 textLength, const WideString& searchText, int32& foundStartPos)
{
    ErrorCode status = kFailure;
    
  do
  {
        if (!m_StoryUIDRef || searchText.CharCount()<=0) break;

    ISession* currSess = GetExecutionContextSession();

    InterfacePtr<IK2ServiceRegistry> serviceRegistry(currSess, UseDefaultIID());
    if (!serviceRegistry) break;

    InterfacePtr<IK2ServiceProvider> serviceProvider(serviceRegistry->QueryServiceProviderByClassID(kTextWalkerService, kTextWalkerServiceProviderBoss));
    if (!serviceProvider) break;

    InterfacePtr<IWorkspace> sessionWorkSpace(currSess->QueryWorkspace());
    if (!sessionWorkSpace) break;

#if(defined ID_CS5 || defined ID_CS5_5 || defined ID_CS6 || defined ID_CC || defined ID_CC2014 || defined ID_CC2015 || defined ID_CC2017 || defined ID_CC2018 || defined ID_CC2019 || defined ID_CC2020 || defined ID_CC2021 || defined ID_CC2022 || defined ID_CC2023)
    InterfacePtr<IFindChangeOptions>
    findChangeOptions(static_cast<IFindChangeOptions*>
                (::CreateObject(kSpellCheckFindChangeDataBoss, IID_IFINDCHANGEOPTIONS)));
#else
    InterfacePtr<IFindChangeOptions> findChangeOptions((IFindChangeOptions*)sessionWorkSpace->QueryInterface(IID_IFINDCHANGEOPTIONS)); 
#endif
    if (!findChangeOptions)
      break;
    findChangeOptions->SetFindString(searchText, IFindChangeOptions::kTextSearch);

    InterfacePtr<ITextWalker> textWalker(serviceProvider, UseDefaultIID());
    if (!textWalker) break;

    if (!textWalker->IsWalking())
    {
      InterfacePtr<ITextModel> textModel(m_StoryUIDRef, UseDefaultIID());
      if (!textModel) break;

      InterfacePtr<ITextWalkerScope> textWalkerScope(Utils<IWalkerScopeFactoryUtils>()->QueryRangeWalkerScope(textModel, textStart, textLength));
      if (!textWalkerScope) break;

      InterfacePtr<ITextWalkerClient> textWalkerClient(static_cast<ITextWalkerClient*>(::CreateObject2<ITextWalkerClient>(kFindChangeClientBoss)));
      if (!textWalkerClient) break;

      textWalker->Initialize(textWalkerClient, textWalkerScope, findChangeOptions, nil);
    }

    CAlert::SetShowAlerts(kFalse);
    
    InterfacePtr<ICommand> findCmd(CmdUtils::CreateCommand(kFindTextCmdBoss));
    InterfacePtr<IFindChangeCmdData> findChangeCmdData(findCmd, UseDefaultIID());  
    if (!findChangeCmdData) break;

    findChangeCmdData->SetTextWalker(textWalker);
    findChangeCmdData->SetRange(m_StoryUIDRef, textStart, textStart+textLength);

    status = CmdUtils::ProcessCommand(findCmd);
    if (status != kSuccess) break;
    
    CAlert::SetShowAlerts(kTrue);

    // Get the found position
    int32 foundEndPos = 0;
    findChangeCmdData->GetRange(foundStartPos, foundEndPos);

    textWalker->Halt();

    status = (findChangeCmdData->GetFindChangeResult() != IFindChangeService::kFailure && foundStartPos >= textStart && foundStartPos <= (textStart + textLength)) ? kSuccess : kFailure;
  } 
  while(kFalse);

    return status;
}

 

 

 

This topic has been closed for replies.

2 replies

Legend
April 18, 2023

Is this about a generic find-change operation, as per the comment?

Why are you then using kSpellCheckFindChangeDataBoss? Sure, when I search the SDK for text walker the spell check example comes up first, but there is also SnpFindAndReplace ...

That stretch of "defined ID…" looks also suspicious - it will fall back to the #else approach with every new version or when the expected macro somehow is missing. Do you really still support pre CS5 as default case? Does the compiler produce code on the intended side of the #if #else ?

Beyond that, performance is not in a SDK, but in the executing application. If you think your current version is behaving differently compared to an earlier one, use a profiler on both to drill down on the code that's actually wasting the time.

dorinhoAuthor
Participating Frequently
April 25, 2023

Thank you! I will check it.

Community Expert
April 18, 2023

HI @dorinho,

This would require elaborate testing before a conclusion can be drawn and since you said this happens not with all text it becomes all the more hard to test. Is there any possibility that you could open a technical support ticket with Adobe, as that would be the best and I suppose the only way to get some help on this. In the meanwhile I am tagging @Rishabh_Tiwari to this thread so that if possible he can connect to the Adobe InDesign team and ask if any changes were made to this portion of the codebase.

-Manan

-Manan
dorinhoAuthor
Participating Frequently
April 18, 2023

Thank you for your enthusiastic reply. Next I will investigate what kind of data will slow down. If technical support is needed, I will propose separately.